Free C++ Institute CPA Exam Actual Questions

The questions for CPA were last updated On Nov 21, 2024

Question No. 1

What happens when you attempt to compile and run the following code?

#include

using namespace std;

int main()

{

int i = 5;

do {

i??;

cout<

}

while(i >= 0);

return 0;

}

Show Answer Hide Answer
Correct Answer: A

Question No. 2

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class A

{

public:

virtual void Print()=0;

};

class B:public A

{

public:

virtual void Print(){ cout<< "B";}

};

int main()

{

B ob2;

A *obj;

obj = &ob2;

obj?>Print();

}

Show Answer Hide Answer
Correct Answer: A

Question No. 3

What will the variable "age" be in class B?

class A {

int x;

protected:

int y;

public:

int age;

};

class B : protected A {

string name;

public:

void Print() {

cout << name << age;

}

};

Show Answer Hide Answer
Correct Answer: C

Question No. 4

What happens when you attempt to compile and run the following code?

#include

using namespace std;

#define FUN(arg) if(arg) cout<<"Test";

int main()

{

int i=1;

FUN(i<3);

return 0;

}

Show Answer Hide Answer
Correct Answer: D

Question No. 5

What happens when you attempt to compile and run the following code?

#include

using namespace std;

struct {

int x;

char c;

union {

float f;

int i;

};

} s;

int main (int argc, const char * argv[])

{

s.x=10;

s.i=0;

cout << s.i << " " << s.x;

}

Show Answer Hide Answer
Correct Answer: A