Free CPE – C++ Certified Entry-Level 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 CPE – C++ Certified Entry-Level Programmer practice bank. Each includes the answer and explanation. Continue with the interactive practice above to review the full question set.
1How are the C++ identifiers total and Total related?
- A. They always name the same object.
- B. They are distinct identifiers.
- C. They differ only inside functions.
- D. They are both reserved keywords.
2What value is assigned to grade by this code? int score = 85; int grade; if (score >= 90) grade = 1; else if (score >= 80) grade = 2; else grade = 3;
- A. 1
- B. 3
- C. 2
- D. 85
Answer: C
Explanation: The draft states, "If the condition (6.4) yields true the first substatement is executed." The first condition is false, so its else is considered. The nested condition score >= 80 is true, assigning 2 and skipping its else.
Reference: Working Draft, Standard for Programming Language C++ (N3337) — §6.4.1 [stmt.if], paragraph 1
3How many elements does this C++ array have? int values[] = {4, 8, 12};
- A. 2
- B. 3
- C. 4
- D. 12
Answer: B
Explanation: The draft states that for an omitted bound, "the bound is calculated from the number of initial elements". There are three initializers, so the array has three elements, independently of their numeric values.
Reference: Working Draft, Standard for Programming Language C++ (N3337) — §8.3.4 [dcl.array], paragraph 3
4Which complete C++ declaration correctly defines a structure named Item with an int data member named count?
- A. struct Item* count;
- B. struct Item { int count; };
- C. int Item(int count);
- D. struct Item;
Answer: B
Explanation: The class-definition grammar is "class-head { member-specificationopt }". Only struct Item { int count; }; supplies the structure body and its int member. The alternatives declare a pointer, declare a function, or only forward-declare the structure.
Reference: Working Draft, Standard for Programming Language C++ (N3337) — §9 [class], class-specifier grammar; §7 [dcl.dcl], simple-declaration grammar
5Why is int while = 3; invalid as a C++ variable declaration?
- A. An int variable cannot be initialized to 3.
- B. Variable names must start with capitals.
- C. The equals sign is not used in declarations.
- D. while is reserved as a keyword.
Answer: D
Explanation: Section 2.12 says, "The identifiers shown in Table 4 are reserved for use as keywords". Table 4 includes while, so it cannot serve as the variable identifier in this declaration.
Reference: Working Draft, Standard for Programming Language C++ (N3337) — §2.12 [lex.key], paragraph 1 and Table 4
6In this code, which if controls the else branch? if (outer) if (inner) result = 1; else result = 2;
- A. The if whose condition is inner.
- B. The if whose condition is outer.
- C. Both if statements share the else.
- D. Neither; indentation makes else invalid.
Answer: A
Explanation: The grammar rule states, "if the first substatement is also an if statement then that inner if statement shall contain an else part." The else therefore belongs to the inner if. Indentation does not change C++ grammar.
Reference: Working Draft, Standard for Programming Language C++ (N3337) — §6.4.1 [stmt.if], paragraph 1
7Which value is selected by table[1][0] in this C++ declaration? int table[2][3] = {{2, 4, 6}, {8, 10, 12}};
- A. 2
- B. 4
- C. 10
- D. 8
Answer: D
Explanation: The draft says aggregate initializers are applied "in increasing subscript or member order." Arrays are indexed from 0. The first subscript 1 selects the second row, and the second subscript 0 selects its first element, 8.
Reference: Working Draft, Standard for Programming Language C++ (N3337) — §8.5.1 [dcl.init.aggr], paragraph 2; §8.3.4 [dcl.array], paragraphs 1 and 3
8What access do data members of a C++ struct have when no access specifier is written?
- A. Private access.
- B. Protected access.
- C. No access until an access label appears.
- D. Public access.
Answer: D
Explanation: The draft states, "Members of a class defined with the keywords struct or union are public by default." This is the struct default, whereas the class keyword gives a private default.
Reference: Working Draft, Standard for Programming Language C++ (N3337) — §11 [class.access], paragraph 3
9In a C++ block comment beginning with /*, what happens when another /* appears before the closing */?
- A. It is part of the existing comment.
- B. It starts a nested comment level.
- C. It ends the existing comment.
- D. It changes the comment to a line comment.
Answer: A
Explanation: The draft states, "Similarly, the comment characters // and /* have no special meaning within a /* comment." Thus the inner /* is comment content, not a nested opening or terminator.
Reference: Working Draft, Standard for Programming Language C++ (N3337) — §2.8 [lex.comment], paragraph 1
10Which branch executes in if (count) handle_items(); else handle_empty(); when count is an int equal to 0?
- A. Both function calls execute.
- B. handle_items() executes.
- C. Neither function call executes.
- D. handle_empty() executes.
Answer: D
Explanation: The draft states, "A zero value, null pointer value, or null member pointer value is converted to false;". The integer condition is therefore false, selecting the else substatement and calling handle_empty().
Reference: Working Draft, Standard for Programming Language C++ (N3337) — §4.12 [conv.bool], paragraph 1; §6.4.1 [stmt.if], paragraph 1
Topics in this practice bank
These topics describe the available practice for CPE – C++ Certified Entry-Level Programmer. Review the examination outline and its sources for scope and allocation details.
Syntax, Literals, and Operators
- Identify valid C++ syntax elements, keywords, and code structures.
- Recognize C++ built-in data types and corresponding literals.
- Describe the structure and declaration of the main() function and its parameters.
- Apply arithmetic, relational, logical, bitwise, and assignment operators.
- Determine operator precedence, associativity, and the impact on expressions.
- Apply short-circuit logic in control expressions.
- Use basic input/output streams (cin, cout, cerr) and manipulators (endl, setw).
Flow Control and Functions
- Describe and use conditional statements (if, else).
- Use loop constructs (while, do, for) and loop control statements (break, continue).
- Recognize the purpose of the goto statement and labeled statements.
- Apply multiple-selection structures using switch, case, and default keywords.
- Define, declare, and invoke functions with correct syntax.
- Use return statements in typed and void functions.
- Pass arguments by value, by reference, and by pointer.
- Apply basic recursion to solve simple problems.
Vectors and Pointers
- Declare, initialize, and manipulate vectors and arrays, including multidimensional arrays.
- Access vector data using the data() method.
- Declare and initialize pointers, including the use of nullptr.
- Dereference pointers and use the address-of operator (&).
- Perform pointer conversions using static_cast and dynamic_cast.
- Manage dynamic memory with new, delete, and delete[].
Structures and Strings
- Declare and define structures.
- Access structure members using the dot (.) operator.
- Declare vectors of structures and access their fields.
- Declare, initialize, and manipulate std::string objects.
- Perform basic string operations and comparisons.
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 CPE – C++ Certified Entry-Level Programmer details.