Free CPA – C++ Certified Associate Programmer Practice Questions
100 free questions · Answer explanations · No signup required
View examination details, outline and sourcesLoading selected examination banks…
Sample Practice Questions
Try these 10 sample questions from the CPA – C++ Certified Associate Programmer practice bank. Each includes the answer and explanation. Continue with the interactive practice above to review the full question set.
1What is the value of the C++ integer expression 4 + 3 * 2?
- A. 14
- B. 10
- C. 9
- D. 24
Answer: B
Explanation: The additive-expression grammar includes "additive-expression + multiplicative-expression". Thus multiplication forms an operand of addition: 3 * 2 is 6, and 4 + 6 is 10. Evaluating addition first would give 14.
Reference: Working Draft, Standard for Programming Language C++ (N4140) — §5.7 [expr.add], additive-expression grammar
2What is x after int x = 0; if (true) if (false) x = 1; else x = 2;?
- A. 0
- B. 1
- C. 2
- D. The code is ill-formed due to the missing outer else.
3Which C++ declaration declares a function named scale that takes one int argument and returns double?
- A. double scale(int amount);
- B. int scale(double factor);
- C. double (*scale)(int input);
- D. double scale = 0.0;
Answer: A
Explanation: The function-declarator syntax includes "D1 ( parameter-declaration-clause )". With double as the leading type and int in the parameter list, double scale(int); declares the requested function. The pointer declarator instead declares a pointer object.
Reference: Working Draft, Standard for Programming Language C++ (N4140) — §8.3.5 [dcl.fct]/1
4In int* p, count;, which names declare pointer objects?
- A. Both p and count
- B. Only p
- C. Only count
- D. Neither name
Answer: B
Explanation: The declaration rule states: "the type specified for each declarator-id depends on both the decl-specifier-seq and its declarator." The * belongs to the declarator p; count has the unadorned int declarator.
Reference: Working Draft, Standard for Programming Language C++ (N4140) — §8.3 [dcl.meaning]/2; §8.3.1 [dcl.ptr]/1
5A class keeps its balance data member private and exposes a public deposit member function. From ordinary nonfriend code, which operation can respect this encapsulation boundary?
- A. Assigning directly to balance through a class pointer
- B. Calling deposit through a class object
- C. Assigning directly to balance through a derived object
- D. Reading balance directly using the class scope operator
Answer: B
Explanation: The private access rule says a private name "can be used only by members and friends of the class in which it is declared." Ordinary external code can call the public operation, while pointer syntax, inheritance, and scope qualification do not grant access to the private representation.
Reference: Working Draft, Standard for Programming Language C++ (N4140) — §11 [class.access]/1.1
6In the unparenthesized integer expression 20 - 6 - 3, which result follows from C++ associativity?
- A. 17
- B. 11
- C. 23
- D. 29
7How many times does ++count execute in int count = 0; do { ++count; } while (false);?
- A. Zero times
- B. One time
- C. Two times
- D. It repeats without terminating.
8In void logValue(int value, int) { /* body uses only value */ }, what does the unnamed second int parameter mean?
- A. The function accepts only one argument.
- B. The second parameter automatically defaults to zero.
- C. The function accepts a second int argument without naming it.
- D. The declaration is invalid because all parameters need names.
9Given int transform(double);, which declaration defines a pointer to that function?
- A. int* fn(double value) = &transform;
- B. int fn(double) = &transform;
- C. int (*fn)(double argument) = &transform;
- D. double (*fn)(int code) = &transform;
Answer: C
Explanation: The draft notes: "Parentheses do not alter the type of the embedded declarator-id, but they can alter the binding of complex declarators." Parenthesizing *fn makes fn a pointer to a function taking double and returning int. The other forms declare functions or use the wrong function type.
Reference: Working Draft, Standard for Programming Language C++ (N4140) — §8.3 [dcl.meaning]/6; §8.3.1 [dcl.ptr]; §8.3.5 [dcl.fct]
10For struct Engine { int serial; }; struct Pump : Engine { int rate; };, what does a Pump object contain as a result of inheritance?
- A. An Engine base subobject and its own rate member
- B. A pointer to a separately allocated Engine only
- C. Only rate; Engine data is not part of Pump
- D. A single member that replaces both serial and rate
Answer: A
Explanation: The draft says: "The base-specifier-list specifies the type of the base class subobjects contained in an object of the derived class type." A Pump therefore includes an Engine subobject, with serial, as well as its own rate member; inheritance does not imply a separate heap allocation.
Reference: Working Draft, Standard for Programming Language C++ (N4140) — §10 [class.derived]/3
Topics in this practice bank
These topics describe the available practice for CPA – C++ Certified Associate Programmer. Review the examination outline and its sources for scope and allocation details.
Types & Operators
- Apply unary, binary, and ternary operators; understand precedence and associativity.
- Use arithmetic, relational, logical, bitwise, assignment, increment/decrement, and short-circuit operators.
- Apply the ternary conditional operator (?:).
- Recognize predefined standard types, data ranges, and internal representations.
- Use literals in various forms (decimal, octal, hexadecimal, binary, floating-point, char, bool).
- Work with std::string objects, escape sequences, and string operations (e.g., compare, size, substr, insert).
- Declare and manipulate aggregates (vectors, arrays, structures, unions, enums).
- Understand type conversion rules, type casting, promotion, and the sizeof operator.
- Apply declaration modifiers (signed, unsigned, static, const).
Control & Exceptions
- Use conditional statements (if, else), loops (while, do, for), and control flow keywords (break, continue, goto).
- Apply multiple-selection constructs (switch, case, default).
- Understand the use of the return statement to exit functions.
- Understand exception handling mechanisms (try, catch, throw, catch-all).
- Recognize exception hierarchies and use the throw() specifier in function declarations.
Functions & Preprocessor Directives
- Define, declare, and invoke functions with correct syntax.
- Use typed and void functions with appropriate return statements.
- Overload functions and assign default parameter values.
- Pass arguments by value, reference, and pointer.
- Implement recursion.
- Apply conventions for main() function declarations.
- Use preprocessor directives for conditional compilation (#if, #endif, #else, #ifdef).
- Define parameterized and non-parameterized macros and understand macro expansion.
Pointers
- Declare and initialize pointers to variables, objects, functions, and aggregates.
- Dereference pointers and use the address-of operator (&).
- Perform pointer arithmetic and comparisons.
- Manage dynamic memory with new, delete, delete[], and avoid memory leaks.
Classes & Namespaces
- Understand OOP principles: inheritance, encapsulation, polymorphism, abstraction.
- Define classes, apply access specifiers, and use class components with the :: operator and this pointer.
- Declare and invoke constructors and destructors, including default, copy, and explicit constructors.
- Overload class member functions and operators.
- Implement inheritance (single, multiple), manage visibility, and understand access levels.
- Work with class type compatibility, casting between types, and use static_cast, dynamic_cast.
- Override methods, use virtual and polymorphic functions, and apply const in objects and members.
- Use friend classes and functions.
- Define and use namespaces, including anonymous and named namespaces, aliases, and the scope resolution operator (::).
How to use these free practice questions
Choose an answer, check the explanation, and review your progress by chapter. Practice questions and explanations are free to access without signing up.
These are independent study questions, not actual examination items. For examination requirements and official information, view CPA – C++ Certified Associate Programmer details.