C++ Institute CPA Exam Questions
C++ Certified Associate Programmer (Page 7 )

Updated On: 24-Feb-2026

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

#include <iostream>

using namespace std;

int main (int argc, const char * argv[])
{
int x,y;
union t
{
char tab[2];
int i;
};
union t u;
u.tab[0] = 1;
u.tab[1] = 2;
u.i = 0;
x = u.tab[0];
y = u.tab[1];
cout << x << "," << y << "," << u.i;
return 0;
}

  1. compilation fails
  2. It prints: 0,0,0
  3. It prints: 1,2,0
  4. None of these

Answer(s): B



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

#include <iostream>
#include <string>
using namespace std;


class A {
protected:
int y;
public:
int x,z;
A() : x(1), y(2), z(0) { z = x + y; }
A(int a, int b) : x(a), y(b) { z = x + y;}
void Print() { cout << z; }
};


class B : public A {
public:
int y;
B() : A() {}
B(int a, int b) : A(a,b) {}
void Print() { cout << z; }
};


int main () {
A b;
b.Print();
return 0;
}

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

Answer(s): A



Which code, inserted at line 10, generates the output "Hello World"?

#include <iostream>
#include <string>
using namespace std;
string fun(string, string);
int main()
{
string s="Hello";
string *ps;
ps = &s;
//insert code here
return 0;
}


string fun(string s1, string s2)
{
return s1+s2;
}

  1. cout << fun(" World");
  2. cout << fun(*ps);
  3. cout << fun("Hello");
  4. cout << fun("Hello", " World");

Answer(s): D



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

#include <iostream>

using namespace std;

int x=5;
static int y=0;


void myFunction(int a)
{
y=++a;
}


int main (int argc, const char * argv[])
{
int i=0;

myFunction(i);
cout<<y<<" "<<x;
}

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

Answer(s): C



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






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

Join the CPA Discussion