01. Consider the following declaration and statement:
int a = 1, b = 2, c = 3;
a = b = c;
Which two statements about the second line are correct?
(Choose two.)
a) The assignment operator groups from left to right, so a = b is performed before the outer assignment.
b) The assignment operator groups from right to left, so b = c is performed before the outer assignment.
c) Once the statement completes, a still holds 1 while b and c both hold the value 3.
d) Once the statement completes, each of a, b and c holds the value 3 that c supplied.
e) The statement is rejected at compile time, because an assignment may not appear on the right of another assignment.
02. Which two statements about the default label of a switch statement are true?
(Choose two.)
a) A default label written before the case labels still runs only when no case value matches.
b) A switch body made up only of case labels, with no default label, is accepted by the compiler.
c) A default label has to be written after every case label in the switch body.
d) A default label written first makes it run before any case value has been compared.
e) A default label may appear twice as long as each one guards a different value.
03. Four names that appear routinely in C++ source files are listed below.
Which one of them is not a word reserved by the language itself?
a) double
b) while
c) main
d) return
04. Which two statements about static_cast and dynamic_cast are correct?
(Choose two.)
a) Converting an int value to a double is written with static_cast; dynamic_cast is not the right tool.
b) A dynamic_cast is the safer choice for every conversion, so it should replace static_cast wherever it appears.
c) A static_cast may be applied only to pointer values, never to an arithmetic value such as an int.
d) A static_cast conversion is resolved when the program is compiled, while dynamic_cast is checked while it runs.
e) A dynamic_cast converts a double value to an int by discarding the fractional part of the value.
05. A loop is written as:
do { total = total + step; } while (total < 0);
total holds 0 and step holds 5 when the loop is reached. Which two statements about this loop are correct?
(Choose two.)
a) The body never runs at all, because the condition is already false at the moment the loop is reached.
b) The body repeats until total falls below zero, because the condition names the state that ends the loop.
c) The loop may be rewritten as a plain while loop, with the same condition and identical behaviour.
d) The whole statement must be closed with a semicolon, placed after the parenthesis that ends the while clause.
e) The body runs exactly once, because the condition of a do loop is tested after the first pass.
06. Two conditions differ only in the operator that joins them:
if (count > 0 && ++used > 0) { }
if (count > 0 & ++used > 0) { }
Assume count holds 0 when each condition is reached. Which three statements are correct?
(Choose three.)
a) Both conditions leave used unchanged, because a false left operand ends the evaluation in either of the forms.
b) In the first condition ++used is not evaluated, because && abandons its right operand once the left is false.
c) In the second condition ++used is evaluated, because & is a bitwise operator that offers no short-circuit behaviour.
d) The second condition is rejected at compile time, because & may not be used to join two relational tests.
e) Both conditions are false overall, so the body of neither if statement is entered in this program.
07. Each line below is written inside the body of a function.
Which lines would the compiler accept without error?
(Choose three.)
a) int 2ndValue = 7;
b) int first, second = 1, 2;
c) double rate = 2.5;
d) int width = 10, height = 4;
e) char letter = 'A';
08. Consider this counting loop:
for (int i = 1; i <= 5; ++i) cout << i;
How many characters does the loop print, and what is the last of them?
a) Four characters, the last of them 4, because the test stops the loop just before i reaches 5.
b) Six characters, the last of them 5, because the counter of a for statement always begins at 0.
c) Five characters, the last of them 6, because the increment is applied before the body of each pass.
d) Five characters, the last of them 5, because the test still holds when i has the value 5.
09. Which two of the following correctly allocate a single int on the free store and leave it holding the value 8?
(Choose two.)
a) int* p = new int(8);
b) int* p = new int[8];
c) int* p = new int; *p = 8;
d) int* p = new int; p = 8;
e) int p = new int(8);
10. The four fragments below belong to one source file, and a closing brace } is already fixed as its last line.
1. std::cout << "Hi";
2. return 0;
3. #include <iostream>
4. int main() {
Which ordering of the four fragments compiles and prints Hi?
a) 4 → 3 → 1 → 2
b) 3 → 1 → 4 → 2
c) 3 → 4 → 1 → 2
d) 3 → 4 → 2 → 1