C++ Institute CPA-21-02 Practice Exam Questions & Answers

5 Free Questions · Last reviewed: September 17, 2026 · Prepared & Reviewed by the ValidExamDumps Editorial Team

Exam Facts

C++ Institute CPA-21-02 Exam Details

Key details for this exam, checked against the published exam outline

257 Practice Questions (Our Bank)
65 minutes Exam Duration
70% Passing Score
Exam Code
CPA-21-02
Full Name
CPA - C++ Certified Associate Programmer Exam
Issuing Body
C++ Institute
Question Format (Our Bank)
Multiple Choice
Exam Fee
USD 325. USD 375 (Exam + Retake)
Delivery
Pearson VUE Test Center or Pearson VUE OnVUE Online Proctoring
Practice Questions

Free CPA-21-02 Practice Questions

Each question shows the correct answer and an explanation of why it is right

VA
ValidExamDumps Editorial Team Every question and its answer is checked by our CPA-21-02 exam preparation team, who also write the explanation shown with each one. How we research and review these pages

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

#include

#include

using namespace std;

class B;

class A {

int age;

public:

A () { age=5; };

friend class B;

};

class B {

string name;

public:

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

void Print(A ob) {

cout << name << ob.age;

}

};

int main () {

A a;

B b;

b.Print(a);

return 0;

}

Correct Answer: A
Explanation This question tests understanding of polymorphism and virtual functions. The First class has a virtual Print method. Second inherits from First and overrides Print. When you call Print on a Second object, the overridden version executes, printing 'from Second' twice because the code creates two Second instances or calls the method twice. Without the virtual keyword, the base class method would execute instead, demonstrating why virtual functions are essential for proper polymorphic behavior.

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

#include

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;

}

Correct Answer: D

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

#include

using namespace std;

int main()

{

int x=2, *y, z=3;

y = &z;

cout<

return 0;

}

Correct Answer: D
Explanation This demonstrates loop control with the break statement. The loop starts with i = 0. On the first iteration, i becomes 1, which is not equal to 3, so the program prints 1. On the second iteration, i becomes 2, which is not equal to 3, so the program prints 2. On the third iteration, i becomes 3, which equals 3, so the break statement executes and exits the loop. The output is 12. Without the break, the loop would continue indefinitely.

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

#include

using namespace std;

class A

{

public:

void Print(){ cout<<"A";}

};

class B:public A

{

public:

virtual void Print(){ cout<< "B";}

};

int main()

{

A *obj;

A ob1;

obj = &ob1;

obj?>Print();

B ob2;

obj = &ob2;

obj?>Print();

}

Correct Answer: B

Which code, inserted at line 5, generates the output "ABC"?

#include

using namespace std;

class A {

public:

//insert code here

};

class B:public A {

public:

void Print(){ cout<< "B"; }

};

class C:public B {

public:

void Print(){ cout<< "C"; }

};

int main()

{

A ob1;

B ob2;

C ob3;

A *obj;

obj = &ob1;

obj?>Print();

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

Correct Answer: B
Explanation This question covers struct definitions and how they can reference themselves. Structure 1 is valid with basic data types. Structure 2 is valid because it contains a pointer to the same struct type, which allows self-referential structures like linked lists. Structure 3 is invalid because it tries to embed an instance of itself directly. A struct cannot contain a complete instance of itself as a member, only a pointer to itself. This would create infinite size requirements at compile time.
Get Full Access

257 questions covering all exam domains, starting from $20

Study Guide

What the C++ Institute CPA-21-02 Exam Covers

Exam domains verified against: Official C++ Institute CPA-21-02 exam guide, last checked September 2026.

Domain 1: Absolute Basics

Covers foundational programming concepts including machine and high-level languages, compilation, variables, integers, characters, streams and basic input/output. This is where you learn to write your first working programs and understand how code becomes machine executable.

Domain 2: Flow Control and More Data Types

Explores program flow control, floating point and additional integer types, loops, and operators including logic, bitwise and arithmetic operations. Mastering these allows you to write programs that make decisions and repeat actions based on conditions.

Sample question from this domain above: Q3

Domain 3: Functions

Focuses on function declaration, invocation, parameters, default parameters, inline functions and overloaded functions. Functions let you break large programs into manageable reusable pieces and are essential to writing maintainable code.

Domain 4: Accessing Data and Dealing with Exceptions

Covers type conversion, strings as objects with methods and properties, namespaces, and exception handling. Understanding exceptions helps you write robust code that handles errors gracefully rather than crashing.

Sample question from this domain above: Q2

Domain 5: Fundamentals of the Object-Oriented Approach

Introduces classes, objects, constructors, static members, friend classes and operator overloading. Object-oriented programming organizes code around data and the operations that work on that data, making large projects easier to manage.

Sample question from this domain above: Q5

Domain 6: Class Hierarchy

Explores inheritance, base classes, subclasses, types of inheritance and multiple inheritance. Inheritance lets you create new classes based on existing ones, avoiding code duplication and building organized hierarchies of related types.

Sample question from this domain above: Q4

Domain 7: More on Classes

Delves into polymorphism, virtual methods, abstract classes and abstraction. These advanced class concepts allow objects of different types to behave differently while using the same interface, enabling flexible and extensible designs.

Sample question from this domain above: Q1

Domain 8: The Basics of Functions

Focuses on exceptions in programming, covering what exceptions are, how to catch and throw them, exception class hierarchies and defining custom exceptions. This topic teaches defensive programming practices that keep applications stable when unexpected situations occur.

FAQ

CPA-21-02 Exam FAQ

Common questions about the exam itself

What prior experience do I need before taking the CPA-21-02 exam?
The C++ Institute does not list formal prerequisites for CPA-21-02. However, the exam assumes you have working knowledge of C++ fundamentals and some programming experience. Most candidates benefit from completing the C++ Essentials 2 course beforehand, which is specifically designed to prepare you for this certification.
How hard is the CPA-21-02 exam and what makes it challenging?
CPA-21-02 tests practical programming ability across eight major topic areas from variables through object-oriented design. The hardest areas for most candidates are Class Hierarchy and More on Classes, which require understanding inheritance, polymorphism and virtual methods. These concepts are abstract and take time to internalize through hands-on practice.
How long should I spend studying for CPA-21-02?
Most candidates need 40 to 60 hours of focused study plus hands-on coding practice. This typically takes 4 to 8 weeks if you study part-time. The exact timeline depends on your current C++ skills and how much time you can dedicate each week.
Can I retake CPA-21-02 if I fail?
Yes, there is no limit to retakes of a failed exam. If your voucher does not include a free retake option, you must purchase a new voucher through the OpenEDG Store. You can schedule a retake at any time after your first attempt.
What happens on exam day when I take CPA-21-02?
Your exam appointment is 75 minutes total: about 10 minutes for tutorial and non-disclosure agreement, then 65 minutes to answer 40 questions. You can test at a Pearson VUE test center or online via OnVUE proctoring. Either way, you need a valid ID and a distraction-free environment.
How much does the CPA-21-02 exam cost?
The exam costs USD 325 for a single attempt. If you want the option to retake it for free if you fail, the combined price is USD 375. You can purchase the exam directly or buy a voucher from the OpenEDG Voucher Store.
What format are the CPA-21-02 questions?
The exam has 40 questions in a mix of single-choice and multiple-choice formats. Each question carries different point values based on complexity. You need to score 70% overall to pass, which means earning enough points across all questions rather than a fixed number correct.
How does CPA-21-02 relate to other C++ Institute exams?
CPA-21-02 is the intermediate level C++ certification. Below it is CPE (Entry-Level), which covers only the first few topics. Above it is CPP (Professional), which builds on CPA foundations and adds advanced topics like STL containers and algorithms. Most people follow this progression.
How long is the CPA-21-02 certification valid for?
The C++ Institute does not publish an expiration date for the CPA certification. Once you pass, your credential does not expire, though the vendor may retire or update the exam version itself, which happened when CPA-21-02 became the active version replacing CPA-21-01.
What job roles benefit from having the CPA-21-02 certification?
CPA-21-02 is suited for junior and mid-level C++ developers, software engineers, and programmers looking to formalize their C++ skills. It is also valuable for students entering the software industry and for developers transitioning from other languages. The certification shows employers you can write correct, efficient C++ code using proper object-oriented techniques.