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

The questions for CPA-21-02 were last updated On Jan 18, 2025

Question No. 1

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

#include

#include

using namespace std;

class Second;

class Base {

int age;

public:

Base () { age=5; };

friend void set(Base &ob, Second &so);

void Print() { cout << age;}

};

class Second {

string name;

public:

friend void set(Base &ob, Second &so);

void Print() { cout << name;}

};

void set(Base &ob, Second &so) {

ob.age = 0; so.name = "Bill";

}

int main () {

Base a;

Second b;

set(a,b);

a.Print();

b.Print();

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;

#include

using namespace std;

class First

{

public:

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

};

int main()

{

First t[2];

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

t[i].Print();

}

Show Answer Hide Answer
Correct Answer: B

Question No. 3

What happens if characters 'w', 'o', 'r', 'l' and 'd' are entered as input?

#include

#include

using namespace std;

int main()

{

string s1 = "Hello";

string s2;

getline( cin, s2 );

cout << s1 + s2;

return( 0 );

}

Show Answer Hide Answer
Correct Answer: A

Question No. 4

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

#include

using namespace std;

int main(){

int i = 1;

if (i++==1) {

cout << i;

} else {

cout << i-1;

}

return 0;

}

Show Answer Hide Answer
Correct Answer: D

Question No. 5

What is the expected result of the following program?

Show Answer Hide Answer
Correct Answer: B