C++ CPE study materials
C++ CPE study resources

C++ CPE: C++ Essentials 1 (CP101 / CPPE1): Procedural Fundamentals

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

All guide sections

C++ Essentials 1 (CP101 / CPPE1): Procedural Fundamentals

The C++ Essentials 1 (CP101 / CPPE1) domain tests procedural C++ fundamentals: the type system and conversions, expression evaluation, control flow, function semantics, arrays, pointers, references, and basic console/string I/O. Questions tend to be short programs or single expressions where one precise rule decides the result, so the mark goes to candidates who can trace conversions and lifetimes rather than guess output.

Types, conversions, and expressions

  • Integral promotions happen before arithmetic: char/short promote to int; bool promotes to int.
  • The usual arithmetic conversions then find a common type. If one operand is unsigned and the other is a signed type that cannot represent all unsigned values (typically int vs unsigned int), the signed operand converts to unsigned.
  • Precedence and associativity matter: postfix ++ binds tighter than *, so *p++ increments the pointer; (*p)++ increments the pointee.
  • && and || short-circuit; the right operand is not evaluated when the result is already known.

Control flow and functions

  • switch case labels must be integral constant expressions; execution falls through without break.
  • Overload resolution prefers exact matches, then promotions, then standard conversions; user-defined conversions come later.
  • Default arguments are supplied at the call site and are not part of the function type.
  • A static local is initialized once and persists for the program lifetime.

Arrays, pointers, references

  • An array name decays to a pointer to its first element in most expressions, but not in sizeof, &, or when binding to a reference to array.
  • Pointer arithmetic is scaled by the pointed-to type; forming a pointer more than one past the end is undefined.
  • A reference must bind at initialization and cannot be reseated; a pointer can be null and reassigned.

Worked example

unsigned int u = 3;
int i = -1;
std::cout << (i < u) << ' ' << (i + u);

i < u triggers the usual arithmetic conversions: i becomes unsigned int (4294967295 on a 32-bit unsigned), so the comparison is false and prints 0. i + u is also computed in unsigned int: 4294967295 + 3 wraps modulo 2^32 to 2, so the second output is 2.

Traps that cost marks

  • Assuming signed comparison when an unsigned operand is present.
  • Reading *p++ as (*p)++.
  • Forgetting break in switch.
  • Using sizeof(array) inside a function where the parameter is a pointer.
  • Returning a reference to a local automatic variable.