C++ Institute CPA-21-02 Exam
CPA - C++ Certified Associate Programmer (Page 2 )

Updated On: 1-Feb-2026

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

class A {
int x;
protected:
int y;
public:
int age;
A () { age=5; };
};

class B : public A {
string name;
public:
B () { name="Bob"; };
void Print() {
cout << name << age;
}
};

  1. public
  2. private
  3. protected
  4. None of these

Answer(s): A



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

#include <iostream>
#include <string>

using namespace std;

class A {
public:
string s;
A(string s) { this?>s = s; }
};

class B {
public:
string s;
B (A a) { this?>s = a.s; }
void print() { cout<<s; }
};

int main()
{
A a("Hello world");
B b=a;

  1. print();
    }
  2. It prints: Hello world
  3. It prints: Hello
  4. Compilation error
  5. None of these

Answer(s): A



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

#include <iostream>

using namespace std;

int op(int x, int y);

int main()
{
float *pf;
float f=0.9;
pf=&f;
cout << op(1, *pf);
return 0;

}

int op(int x, int y)
{
return x*y;
}

  1. It prints: 0
  2. It prints: 0.5
  3. It prints: 1
  4. It prints: ?1

Answer(s): A



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

#include <iostream>
#include <string>

using namespace std;

class First
{
string *s;
public:
First() { s = new string("Text");}
~First() { delete s;}
void Print(){ cout<<*s;}
};
int main()
{
First FirstObject;

FirstObject.Print();
FirstObject.~First();
}

  1. It prints: Text
  2. Compilation error
  3. Runtime error.
  4. None of these

Answer(s): C



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

#include <iostream>

using namespace std;

class A
{
public:
virtual void Print(){ cout<<"A";}
};
class B:public A
{
public:
void Print(){ cout<< "B";}
};
int main()
{
A *obj;
A ob1;
obj = &ob1;
obj?>Print();
B ob2;
obj = &ob2;
obj?>Print();
}

  1. It prints: AB
  2. It prints: AA
  3. It prints: BA
  4. It prints: BB

Answer(s): A



Viewing page 2 of 53
Viewing questions 6 - 10 out of 257 questions



Post your Comments and Discuss C++ Institute CPA-21-02 exam prep with other Community members:

Join the CPA-21-02 Discussion