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

Updated On: 30-Jan-2026

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

#include <iostream>

using namespace std;

int compare(int, int);

int main()
{
int x = compare(10, 20);
cout << x;
return 0;
}


int compare(int i, int j)
{
return i<j;
}

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

Answer(s): C



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

#include <iostream>

using namespace std;


int main()
{
int x,y=10;
float f;
f = 5.90;
cout << f << ", ";
x=f;
cout << x <<", ";
f=y;
cout << f;
return 0;
}

  1. It prints: 5, 5, 10.00
  2. It prints: 5.9, 5, 10
  3. It prints: 6, 5, 10
  4. It prints: 6, 5, 10.00

Answer(s): B



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

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


const int size = 3;
class A {
public:
string name;
A() { name = "Bob";}
A(string s) { name = s;}
A(A &a) { name = a.name;}
};
class B : public A {
public:
int *tab;
B() { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;}
B(string s) : A(s) { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;}
~B() { delete tab; }
void Print() {
for (int i=0; i<size; i++) cout << tab[i];
cout << name;
}
};
int main () {
B b1("Alan");
B b2;
b1.tab[0]=0;
b1.Print(); b2.Print();
return 0;
}

  1. It prints: Alan
  2. It prints: 111
  3. It prints: 011Alan111Bob
  4. It prints: 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;
B *obj;
obj = &ob2;
obj?>Print();
obj = &ob3;
obj?>Print();
}

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

Answer(s): C



What is the output of the program?

#include <iostream>
using namespace std;


class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=10) {age = a;}
void Print() { cout << age;}
};


int Base::age=0;

int main () {
Base a,*b;
b = new Base();
a.setAge();
b?>setAge(20);
a.Print();
b?>Print();
return 0;
}

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

Answer(s): A



Viewing page 8 of 45
Viewing questions 36 - 40 out of 220 questions



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

Join the CPA Discussion