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

7 Free Questions Last reviewed November 1, 2026 Prepared & Reviewed by the ValidExamDumps Editorial Team

257 Practice Questions (Our Bank)
65 minutes Exam Duration
70% Passing Score
Exam Facts

C++ Institute CPA-21-02 Exam Details

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

Exam Code
CPA-21-02
Full Name
CPA - C++ Certified Associate Programmer Exam
Issuing Body
C++ Institute
Question Format (Our Bank)
Multiple Choice
Official 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

Question 1 Domain 2 Flow Control and More Data Types

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

#include

using namespace std;

int fun(int x);

int main() {

cout << fun(0);

return 0;

}

int fun(int x) {

if(x > 0)

return fun(x-1);

else

return 100;

}

Correct Answer C
Explanation This question tests understanding of switch statements and control flow. When i equals 2, the switch statement checks each case. Since there's no case 2, it falls through to the default case which prints 'world'. Without a break statement after case 1, execution would continue through subsequent cases, but since case 1 doesn't match, this doesn't apply here. The default case always executes when no other case matches.

Question 2 Domain 4 Accessing Data and Dealing with Exceptions

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

#include

using namespace std;

int main()

{

const char *s;

char str[] = "Hello";

s = str;

while(*s) {

cout << *s++;

}

return 0;

}

Correct Answer B
Explanation This demonstrates pointers and dereferencing. The pointer ptr stores the address of variable x, which is initialized to 0. When cout prints ptr, it shows the address value. When cout prints *ptr, it dereferences the pointer to show the value stored at that address, which is 0. So the output is the address followed by 0. Option A correctly identifies that both the address and the value 0 are printed.

Question 3 Domain 6 Class Hierarchy

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

#include

using namespace std;

int main(){

int i = 1;

if (i++==1) {

cout << i;

} else {

cout << i-1;

}

return 0;

}

Correct Answer D
Explanation This tests inheritance and the using keyword. Class B inherits privately from A, but uses the 'using' declaration to make A's public member x accessible. When c1 is created with the default constructor, x is set to 1. When c2 is created with the argument 5, x is set to 5. The cout statement prints both values, producing 1 and 5. The 'using' declaration allows access to the inherited member despite private inheritance.

Get the complete CPA-21-02 question set $20$40

Get Full Access

Question 4 Domain 4 Accessing Data and Dealing with Exceptions

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

#include

using namespace std;

class complex{

double re;

double im;

public:

complex() : re(0),im(0) {}

complex(double x) { re=x,im=x;};

complex(double x,double y) { re=x,im=y;}

void print() { cout << re << " " << im;}

};

int main(){

complex c1(1,2);

c1.print();

return 0;

}

Correct Answer C
Explanation The expression 1.0/2*2/1*2/4*4 evaluates left to right: 0.5*2=1.0, then 1.0/1=1.0, then 1.0*2=2.0, then 2.0/4=0.5, then 0.5*4=2.0. When assigned to an int, it truncates to 2. This tests your understanding of operator precedence and type conversion from floating point to integer.

Question 5 Domain 1 Absolute Basics

Which of the following structures are correct?

1:

struct s1{

int x;

char c;

};

2:

struct s2{

float f;

struct s2 *s;

};

3:

struct s3{

float f;

in i;

}

Correct Answer A, B
Explanation This question asks which struct declarations are syntactically correct. Struct s1 is valid with an int and char member. Struct s2 is valid with a float member and a self-referential pointer to s2, which is a common technique for linked structures. Struct s3 has a syntax error because 'in' is not a valid type. It should be 'int'. Therefore, only structures 1 and 2 are correct, making option A the right answer.

Question 6 Domain 3 Functions

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

#include

#include

using namespace std;

string fun(string, string);

int main()

{

string s="Hello";

cout << fun(s, " World");

return 0;

}

string fun(string s1, string s2)

{

return s1+s2;

}

Correct Answer A
Explanation This tests function declaration and type conversion. The function f is declared to return an int and takes two int parameters. When called with arguments 20 and 10, it returns their difference, which is 10. However, the return value is assigned to a float variable b, so 10 is converted to 10.0. When printed as an integer using %d, the output is 2, which suggests the function actually performs division. The correct answer confirms the output is 2.

Question 7 Domain 5 Fundamentals of the Object-Oriented Approach

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

#include

using namespace std;

void fun(char*);

int main()

{

char t[4]={'0', '1', '2', '3'};

fun(&t[0]);

return 0;

}

void fun(char *a)

{

cout << *a;

}

Correct Answer C
Explanation This demonstrates constructors and member functions in classes. The First class constructor allocates a Person object and initializes its name to 'John' and age to 30. The Print function outputs these values. In main, c1 calls Print once, outputting 'John 30'. Then c2 also calls Print, outputting 'John 30' again. Since c2 also uses the default constructor, it creates its own Person with the same initial values, resulting in the output appearing twice.
Study Guide

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

Exam domains verified against the Official C++ Institute CPA-21-02 exam guide, last checked November 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.

Sample question from this domain above Q5

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 Q1

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.

Sample question from this domain above Q6

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 questions from this domain above Q2Q4

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 Q7

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 Q3

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.

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.

Other C++ Institute Exams

Free practice questions for more C++ Institute certification exams

All C++ Institute exams