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

Updated On: 1-Feb-2026

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

#include <iostream>
using namespace std;

int main(){
int *i;
i = new int;
*i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4;
cout << *i;
return 0;
}

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

Answer(s): C



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

#include <iostream>

using namespace std;

void fun(char*);

int main()
{
char t[4]={'0', '1', '2', '3'};
fun(&t[2]);
return 0;
}
void fun(char *a)
{
cout << *a;

}

  1. It prints: 2
  2. It prints: 21
  3. It prints: 00
  4. It prints: 02

Answer(s): A



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

#include <iostream>
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();
}

  1. It prints: BBB
  2. It prints: AAA
  3. It prints: ABC
  4. It prints: ABB

Answer(s): B



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

#include <iostream>
#include <string>

using namespace std;

class complex{
double re, im;
public:
complex() : re(1),im(0.4) {}
complex operator?(complex &t);
void Print() { cout << re << " " << im; }
};

complex complex::operator? (complex &t){
complex temp;
temp.re = this?>re ? t.re;
temp.im = this?>im ? t.im;
return temp;
}

int main(){
complex c1,c2,c3;
c3 = c1 ? c2;
c3.Print();
}

  1. It prints: 1 0.4
  2. It prints: 2 0.8
  3. It prints: 0 0
  4. It prints: 1 0.8

Answer(s): C



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

#include <iostream>
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double x) { re=x,im=x;};
complex(double x,double y) { re=x,im=y;}
void print() { cout << re << " " << im;}

};

int main(){
complex c1;
c1 = 3.0;
c1.print();
return 0;
}

  1. It prints: 0 0
  2. It prints: 1 1
  3. It prints: 3 3
  4. Compilation error

Answer(s): C



Viewing page 8 of 53
Viewing questions 36 - 40 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