C++ CPA study materials
C++ CPA study resources

C++ CPA: C++ types, expressions, functions and control flow

C++ CPA · Work through your exam, one topic at a time.

All guide sections

C++ types, expressions, functions and control flow

State the language model

A C++ exercise needs the relevant language version, declarations and input assumptions. Use the actual included standard headers rather than depend on a compiler’s accidental transitive includes. Distinguish a translation error, a defined result, an implementation-dependent choice and undefined behavior. A successful run on one implementation is evidence about that run, not proof of a guarantee the language does not provide. Do not assign a predictable numeric answer to an expression whose behavior is undefined.

Trace values and decisions

Types affect arithmetic and conversions. With positive integral operands, integer division discards the fractional part; converting an operand to floating point before division changes the operation. Precedence determines grouping, while sequencing determines when evaluations occur; they are not interchangeable. Short-circuit logical operators can skip the right operand. Increment operators have different value effects, and unsequenced modifications to the same object require particular care. A modern language-version rule must not be replaced by a remembered pre-C++17 assumption.

Follow the actual path

For a loop, record initialization, condition, body and update separately. A do-while executes its body before checking its condition. A break exits the nearest relevant loop or switch, while continue advances according to the enclosing loop’s rules. A switch can fall through when no transfer prevents it. Braces clarify nested conditional association and keep a visual layout from misleading the trace. Compare assignment with equality rather than assuming a condition only reads its operands.

Understand function interfaces

A value parameter is a distinct parameter object, while a reference can refer to the caller’s object. A pointer passed by value can still designate a mutable caller object. Overloading depends on the relevant signature and resolution rules, not merely a different return type. Default arguments fill omitted trailing arguments under their declaration rules. Recursion needs a reachable base case and progress within valid input and resource bounds. These are independent written foundations for CPA/CPP study, with related advanced library work identified as extension or prerequisite practice rather than the official distribution or proof of practical competence.