Exam Details

  • Exam Code
    :CPA-21-02
  • Exam Name
    :CPA - C++ Certified Associate Programmer
  • Certification
    :C++ Institute Certifications
  • Vendor
    :C++ Institute
  • Total Questions
    :257 Q&As
  • Last Updated
    :Jul 18, 2025

C++ Institute C++ Institute Certifications CPA-21-02 Questions & Answers

  • Question 161:

    What will the variable "y" be in class B?

    class A {

    int x;

    protected:

    int y;

    public:

    int age;

    };

    class B : protected A {

    string name;

    public:

    void Print() {

    cout << name << age;

    }

    };

    A. public

    B. private

    C. protected

    D. None of these

  • Question 162:

    How many copies of the value member are stored in memory during program execution?

    A. as many as objects of the A class plus one

    B. as many as obiects of the A class and its inheritants

    C. as many as objects of the A class

    D. one

  • Question 163:

    Which code lines inserted independently instead of the comment will make the following program work correctly? (Choose three.)

    A. int main (int argc, char *argv[])

    B. int main (int c, char *v[])

    C. int main

    D. void main ()

  • Question 164:

    What is the output of the program?

    #include

    #include

    using namespace std;

    union t

    {

    char c;

    int i;

    };

    class First

    {

    union t u;

    public:

    First() {

    u.c

    = 'A';

    }

    void Print(){

    cout << u.c;

    }

    };

    int main()

    {

    First *t = new First();

    t?>Print();

    }

    A.

    Garbage value

    B.

    It prints: A

    C.

    It prints: A 65

    D.

    Compilation error

  • Question 165:

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

    #include

    using namespace std; int main()

    {

    int i = 5;

    cout<<"Hello World" << ++i;

    return 0;

    }

    A. It prints: Hello World6

    B. It prints: Hello

    C. It prints: World

    D. It prints: Hello World5

  • Question 166:

    Which code, inserted at line 19, generates the output "23"?

    #include

    #include

    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:

    int y;

    void set() { y = 4; z = "John"; }

    void Print() {

    //insert code here

    }

    };

    int main () {

    B b;

    b.set();

    b.Print();

    return 0;

    }

    A. cout << y << z;

    B. cout << y << A::z;

    C. cout << A::y << A::z;

    D. cout << B::y << B::z;

  • Question 167:

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

    #include

    using namespace std;

    int compare(int, int);

    int main()

    {

    int x = compare(10, 20);

    cout << x;

    return 0;

    }

    int compare(int i, int j)

    {

    return i

    }

    A. It prints: 0

    B. It prints: 2

    C. It prints: 1

    D. It prints: 10

  • Question 168:

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

    #include

    #include

    using namespace std;

    const int size = 3;

    class A {

    public:

    string name;

    A() { name = "Bob";}

    A(string s) { name = s;}

    A(A anda) { name = a.name;}

    };

    class B : public A {

    public:

    int *tab;

    B() { tab = new int[size]; for (int i=0; i

    B(string s) : A(s) { tab = new int[size]; for (int i=0; i

    ~B() { delete tab; }

    void Print() {

    for (int i=0; i

    cout << name;

    }

    };

    int main () {

    B b1("Alan");

    B b2;

    b1.tab[0]=0;

    b1.Print(); b2.Print();

    return 0;

    }

    A. It prints: Alan

    B. It prints: 111

    C. It prints: 011Alan111Bob

    D. It prints: 0

  • Question 169:

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

    #include

    #include

    using namespace std;

    class A {

    public:

    int age;

    A () { age=5; };

    };

    class B : private A {

    string name;

    public:

    B () { name="Bob"; };

    void Print() {

    cout << name << age;

    }

    };

    int main () {

    B b,*ob;

    ob = andb;

    ob?>age = 10;

    ob?>Print();

    return 0;

    }

    A. It prints: Bob55

    B. It prints: Bob1

    C. It prints: 10

    D. Compilation error

  • Question 170:

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

    #include

    #include

    using namespace std;

    class Second;

    class Base {

    int age;

    public:

    Base () { age=5; };

    friend void set(Base andob, Second andso);

    void Print() { cout << age;}

    };

    class Second {

    string name;

    public:

    friend void set(Base andob, Second andso);

    void Print() { cout << name;}

    };

    void set(Base andob, Second andso) {

    ob.age = 0; so.name = "Bill";

    }

    int main () {

    Base a;

    Second b;

    set(a,b);

    a.Print();

    b.Print();

    return 0;

    }

    A. It prints: 0Bill

    B. Compilation error

    C. It prints: Bill0

    D. None of these

Tips on How to Prepare for the Exams

Nowadays, the certification exams become more and more important and required by more and more enterprises when applying for a job. But how to prepare for the exam effectively? How to prepare for the exam in a short time with less efforts? How to get a ideal result and how to find the most reliable resources? Here on Vcedump.com, you will find all the answers. Vcedump.com provide not only C++ Institute exam questions, answers and explanations but also complete assistance on your exam preparation and certification application. If you are confused on your CPA-21-02 exam preparations and C++ Institute certification application, do not hesitate to visit our Vcedump.com to find your solutions here.