C++ Institute CPA Exam
C++ Certified Associate Programmer (Page 3 )

Updated On: 26-Jan-2026

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

#include <iostream>

using namespace std;

class BaseC
{
public:
int *ptr;
BaseC() { ptr = new int(10);}
BaseC(int i) { ptr = new int(i); }
~BaseC() { delete ptr; }
};
void fun(BaseC x);


int main()
{
BaseC *o = new BaseC(5);
fun(*o);
}


void fun(BaseC x) {
cout << "Hello:"<<*x.ptr;
}

  1. It prints: Hello:50
  2. It prints: Hello:10
  3. It prints: Hello:5
  4. Compilation error

Answer(s): C



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

#include <iostream>

using namespace std;

class First
{
public:
virtual void Print(){ cout<<"from First";}
};
class Second:public First
{
public:
void Print(){ cout<< "from Second";}
};
void fun(First *obj);
int main()
{
First FirstObject;
fun(&FirstObject);
Second SecondObject;
fun(&SecondObject);
}
void fun(First *obj)
{
obj?>Print();
}

  1. It prints: from First
  2. It prints: from Firstfrom First
  3. It prints: from Firstfrom Second
  4. It prints: from Secondfrom Second

Answer(s): C



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

#include <iostream>

using namespace std;

int min(int a, int b);

int main()
{
int min(int,int);
int b;
b = min(10,20);
cout << b;
return 0;
}


int min(int a, int b)
{
return(b);
}

  1. It prints: 20
  2. It prints: 10
  3. It prints: 1020
  4. It prints: 2010

Answer(s): A



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

#include <iostream>

using namespace std;

int main()
{
union un
{
int x;
char c;
};
union un u1 = {10};
union un u2 = {'a'};
union un u3 = {20, 'a'};
cout<<u1.x;
cout<<u2.c;
cout<<u3.c;
return 0;
}

  1. It prints: 10aa
  2. It prints: 10a20a
  3. It prints: 1a
  4. Compilation error

Answer(s): D



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

#include <iostream>
using namespace std;

int main() {
int i, j;
for(i = 0; i < 2; i++) {
for(j = i; j < i + 1; j++)
if(j == i)
continue;
else
break;
}
cout << j;
return 0;
}

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

Answer(s): C



Viewing page 3 of 45
Viewing questions 11 - 15 out of 220 questions



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

Join the CPA Discussion