Free CPA Exam Braindumps
C++ Certified Associate Programmer Questions 81–85 (page: 18)

Updated On: 9-Feb-2026

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

#include <iostream>

using namespace std;


class Test {
float i,j;
};


class Add {
public:
int x,y;
Add (int a=3, int b=3) { x=a; y=b; }
int result() { return x+y;}
};


int main () {
Test test;
Add * padd;
padd = &test;
cout << padd?>result();
return 0;
}

  1. It prints: 6
  2. It prints: 9
  3. Compilation error
  4. It prints: 33

Answer(s): C



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

#include <iostream>

using namespace std;

class BaseC
{
int *ptr;
public:
BaseC() { ptr = new int(10);}
BaseC(int i) { ptr = new int(i); }
~BaseC() { delete ptr; }
void Print() { cout << *ptr; }
};


int main()
{
BaseC *o = new BaseC(5);
o?>Print();
}

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

Answer(s): A



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

#include <iostream>

using namespace std;

int main()
{
const char *s;
char str[] = "Hello ";
s = str;
while(*s) {
cout << *++s;
*s++;
}

return 0;
}

  1. It will print:"el "
  2. The code will not compile.
  3. It will print:"Hello "
  4. It will print garbage value

Answer(s): A



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 :
void print() {
cout << "B ";
}
};
int main() {
B sc[2];
A *bc = (A*)sc;
for (int i=0; i<2;i++)
(bc++)->print();
return 0;
}

  1. It prints: A A
  2. It prints: B B
  3. It prints: A B
  4. It prints: B A

Answer(s): A



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.20;
x=(int) f;
cout << x <<", ";
f=float (y);
cout << f;
return 0;
}

  1. It prints: 5, 10
  2. It prints: 5.2, 10
  3. It prints: 5.20, 10.0
  4. It prints: 5.2, 10.00

Answer(s): A



Viewing page 18 of 45
Viewing questions 86 - 90 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!