C++ Institute CPA-21-02 Exam
CPA - C++ Certified Associate Programmer (Page 3 )

Updated On: 1-Feb-2026

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

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main(void)
{
string s;
s = "Test";

  1. resize (s.size() ? 1);
    cout<<s<<" "<<s.size();
    return 0;
    }
  2. It prints: Test 4
  3. It prints: Test 3
  4. Compilation error
  5. It prints: Tes 3

Answer(s): D



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

#include <iostream>
using namespace std;

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

class B : public A {
public:

B() { x=1;}
};

class C : private B {
public:
C() { x=2;}
};

int main () {
C c1;

cout << c1.x;
return 0;
}

  1. It prints: 210
  2. It prints: 110
  3. It prints: 010
  4. Compilation error

Answer(s): D



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

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

class A {
public:
A() { cout << "A no parameters";}
A(string s) { cout << "A string parameter";}
A(A &a) { cout << "A object A parameter";}
};

class B : public A {
public:
B() { cout << "B no parameters";}
B(string s) { cout << "B string parameter";}
B(int s) { cout << "B int parameter";}
};

int main () {
A a2("Test");
B b1(10);
B b2(b1);
return 0;
}

  1. It prints: A no parametersA no parametersB string parameter
  2. It prints: A string parameterA no parametersB int parameterA object A parameter
  3. It prints: A no parametersB string parameter
  4. It prints: A no parametersA no parameters

Answer(s): B



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



Viewing page 3 of 53
Viewing questions 11 - 15 out of 257 questions



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

Join the CPA-21-02 Discussion