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

Updated On: 26-Jan-2026

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

#include <iostream>

using namespace std;

class A
{
public:
virtual void Print(){ cout<<"A";}
};
class B:public A
{
public:
virtual void Print(){ cout<< "B";}
};
int main()
{
A *obj;
A ob1;
obj = &ob1;
obj?>Print();
B ob2;
obj = &ob2;
obj?>Print();
}

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

Answer(s): A



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

#include <iostream>

using namespace std;

void set(struct person*);
struct person
{
char name[25];
int age;
};
int main()
{
struct person e = {"Steve", 30};
set(&e);
cout<< e.name << " " << e.age;
return 0;
}
void set(struct person *p)
{
p?>age = p?>age + 1;
}

  1. Error: in prototype declaration unknown struct person
  2. Error: in structure
  3. It prints: Steve 31
  4. None of these

Answer(s): C



What happens if you try to compile and run this program?

#include <iostream>


using namespace std;

int main (int argc, const char * argv[])
{
print("Test");
return 0;
}
void print(int c[])
{
cout<<c;
}

  1. It prints: Test
  2. Compilation fails
  3. Program terminates abnormally
  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;
int z;
A() { x=1; y=2; z=3; }
A(int a, int b) : x(a), y(b) { z = x * y;}
void Print() {
cout << z;
}
};


int main () {
A a(2,5);
a.Print();
return 0;
}

  1. It prints: 10
  2. It prints: 2
  3. It prints: 6
  4. It prints: 5

Answer(s): A



What is the output of the program?

#include <iostream>
#include <string>

using namespace std;

int main()
{
string s1="World";
string s2;
s2="Hello" + s1;
cout << s2;
return( 0 );
}

  1. It prints: HelloWorld
  2. It prints: Hello
  3. It prints: World
  4. Compilation error

Answer(s): A



Viewing page 5 of 45
Viewing questions 21 - 25 out of 220 questions



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

Join the CPA Discussion