Free CPA-21-02 Exam Braindumps
CPA - C++ Certified Associate Programmer Questions 126–130 (page: 27)

Updated On: 9-Feb-2026

What is the output of the program?

#include <iostream>
#include <string>

using namespace std;

int main()
{
char str[] = "Hello\0\World\0";
cout << str;
return 0;
}

  1. It prints: Hello
  2. It prints: World
  3. It prints: HW
  4. It prints: World\0World

Answer(s): A



If there is one, point out an error in the program

#include <iostream>

using namespace std;

int main()
{
int c = 'a';
switch(i)
{

case '2':
cout<<"OK";
case '1':
cout<<"Error";
default:
break;
}
return 0;
}

  1. No Error
  2. Use of undeclared identifier 'i'
  3. Illegal use of 'continue'
  4. Illegal use of 'break'

Answer(s): B



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

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

class A {
int x;
protected:
int y;
public:
int z;
A() { x=1; y=2; z=3; }
};
class B : public A {

string z;
public:
void set() { y = 4; z = "John"; }
void Print() { cout << y << A::z; }
};

int main () {
B b;

  1. set();
  2. Print();
    return 0;

    }
  3. It prints: 4John
  4. It prints: 2John
  5. It prints: 23
  6. It prints: 43

Answer(s): D



Which code, inserted at line 10, generate the output "50"?

#include <iostream>
using namespace std;

class Base {
int age;
public:
Base () {
age=5;
};
//insert code here void Print() { cout << age;}
};

void setAge(Base &ob) {ob.age = 0;}

int main () {
Base a;

  1. Print();
    setAge(a);
  2. Print();
    return 0;
    }
  3. friend void setAge(Base ob);
  4. friend void setAge(Base *ob);
  5. friend void setAge(Base &ob);
  6. None of these

Answer(s): C



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

#include <iostream>

using namespace std;

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

  1. It prints: Constructorfrom First
  2. It prints: Constructor
  3. It prints: from First
  4. None of these

Answer(s): A



Viewing page 27 of 53
Viewing questions 131 - 135 out of 257 questions


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

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