Free CPA Exam Braindumps
C++ Certified Associate Programmer Questions 41–45 (page: 10)

Updated On: 9-Feb-2026

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

#include <iostream>

using namespace std;

#include <iostream>

using namespace std;

class First
{
public:
void Print(){ cout<<"from First";}
};


int main()
{
First t[2];
for (int i=0; i<2; i++)
t[i].Print();
}

  1. It prints: from First
  2. It prints: from Firstfrom First
  3. Compilation error
  4. Runtime error.

Answer(s): B



What is the output of the program given below?

#include <iostream>

using namespace std;

int main (int argc, const char * argv[])
{
int i=10;
{
int i=0;
cout<<i;
}
cout<<i;
return 0;
}

  1. 1010
  2. 100
  3. 010
  4. None of these

Answer(s): C



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

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


class A {
public:
int x;
A() { x=0;}
A(int x) { this?>x=x;}
};


class B : private A {
public:
using A::x;
B() { x=1;}
B(int x) {this?>x = x;}
};


int main () {
B c1;
B c2(?5);
cout << c1.x;
cout << c2.x;
return 0;

}

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

Answer(s): B



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 a = 30, b = 1, c = 5, i=10;
i = b < a < c;
cout << i;
return 0;
}

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

Answer(s): D



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

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

class B;


class A {
int age;
public:
A () { age=5; };
friend class B;
};


class B {
string name;
public:
B () { name="Bob"; };
void Print(A ob) {
cout << name << ob.age;
}
};


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

  1. It prints: Bob5
  2. It prints: Bob
  3. It prints: 5
  4. None of these

Answer(s): A



Viewing page 10 of 45
Viewing questions 46 - 50 out of 220 questions


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

AI Tutor AI Tutor 👋 I’m here to help!