Free C++ Institute CPA-21-02 Exam Actual Questions

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

Question No. 1

Which of the structures is incorrect?

1:

struct s1{

int x;

long int li;

};

2:

struct s2{

float f;

struct s2 *s;

};

3:

struct s3{

float f;

struct s3 s;

};

Show Answer Hide Answer
Correct Answer: C

Question No. 2

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

#include

using namespace std;

class A {

public:

void Print(){ cout<<"A"; }

};

class B:public A {

public:

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

};

class C:public B {

public:

void Print(){ cout<< "C"; }

};

int main()

{

A ob1;

B ob2;

C ob3;

A *obj;

obj = &ob1;

obj?>Print();

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

Show Answer Hide Answer
Correct Answer: B

Question No. 3

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

#include

using namespace std;

int op(int x, int y)

{

int i;

i = x + y;

return i;

}

int main()

{

int i=1, j=2, k, l;

k = op(i, j);

l = op(j, i);

cout<< k << "," << l;

return 0;

}

Show Answer Hide Answer
Correct Answer: D

Question No. 4

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

#include

using namespace std;

class First

{

public:

void Print(){ cout<<"from First";}

};

class Second

{

public:

void Print(){ cout<< "from Second";}

};

int main()

{

Second t[2];

for (int i=0; i<2; i++)

t[i].Print();

}

Show Answer Hide Answer
Correct Answer: C

Question No. 5

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

#include

using namespace std;

class A {

public :

void print() {

cout << "A ";

}

};

class B {

public :

void print() {

cout << "B ";

}

};

int main() {

B sc[2];

A *bc = (A*)sc;

for (int i=0; i<2;i++)

(bc++)->print();

return 0;

}

Show Answer Hide Answer
Correct Answer: A