Free CPA Exam Braindumps
C++ Certified Associate Programmer Questions 51–55 (page: 12)

Updated On: 9-Feb-2026

Which code, inserted at line 14, generates the output "3.14 10"?

#include <iostream>
using namespace std;
namespace myNamespace1
{
int x = 5;
int y = 10;
}
namespace myNamespace2
{
float x = 3.14;
float y = 1.5;
}
int main () {
//insert code here
cout << x << " " << y;
return 0;
}

  1. using myNamespace2::y; using myNamespace1::x;
  2. using namespace myNamespace1;
  3. using namespace myNamespace1; using namespace myNamespace2;
  4. using myNamespace1::y; using myNamespace2::x;

Answer(s): D



What is the output of the program?

#include <iostream>
#include <string>

using namespace std;

int main()
{
string s1[]= {"Hello" , "World" };

for (int i=0; i<2; i++) {
cout << s1[i];
}
return( 0 );
}

  1. It prints: HelloWorld
  2. It prints: Hello
  3. It prints: WorldHello
  4. It prints: World

Answer(s): A



Which code, inserted at line 8, generates the output "0102020"?

#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
//insert code here
void Print() { cout << age;}
};

int Base::age=0;

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

  1. void setAge(int a) {age = a;}
  2. void setAge() {age = 20;}
  3. void setAge() {age = 10;}
  4. void setAge(int a=20) {age = a;}

Answer(s): D



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

#include <iostream>

using namespace std;

class First
{
public:
void Print(){ cout<<"from First";}
};
class Second
{
public:
void Print(){ cout<< "from Second";}
};
int main()
{
First FirstObject;
FirstObject.Print();
Second SecondObject;
SecondObject.Print();
}

  1. It prints: from First
  2. It prints: from Firstfrom First
  3. It prints: from Firstfrom Second
  4. It prints: from Secondfrom Second

Answer(s): C



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

#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
char *s = "ABCDEF";
cout << s+2;
return 0;
}

  1. It prints: CDEF
  2. It prints: ABCDEF
  3. It prints: BCDEF
  4. None of these

Answer(s): A



Viewing page 12 of 45
Viewing questions 56 - 60 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!