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

Updated On: 30-Jan-2026

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

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


class A {
int x;
protected:
int y;
public:
int z;
};


class B : private A {
string name;
public:
void set() {
x = 1;
}
void Print() {
cout << x;
}
};


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

  1. It prints: 123
  2. It prints: 1
  3. It prints: ?123
  4. Compilation error

Answer(s): D



What is the output of the program?

#include <iostream>

using namespace std;

#define SQR(x)(x*x)


int main(int argc, char *argv[]) {
int x, y=2;


x = SQR(y);
cout << x << ", " <<y;
return 0;
}

  1. It prints: 3, 2
  2. It prints: 4, 2
  3. It prints: 3, 3
  4. It prints: 9, 2

Answer(s): B



What will be the output of the program?

#include <iostream>

using namespace std;


int main()
{
int i=0;
for(; i<=5; i++)
cout << i;
return 0;
}

  1. 012345
  2. 0123
  3. 5
  4. 6

Answer(s): A



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

#include <iostream>
using namespace std;


class Base {
int age;
public:
class C {
int b;
void PrintC() { cout << b; }
};
Base () {age=5;};
void setAge(int a=20) {age = a;}
void Print() { cout << age;}
};


int main () {
Base a;
a.setAge(10);
a.Print();
return 0;
}

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

Answer(s): C



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

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

  1. It prints: 0Bill
  2. Compilation error
  3. It prints: Bill0
  4. None of these

Answer(s): A



Viewing page 9 of 45
Viewing questions 41 - 45 out of 220 questions



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

Join the CPA Discussion