01. A search runs over a two-dimensional array in a pair of nested loops. As soon as a match is found the code must leave both loops and continue at a single clean-up step written just after them, without adding any state that the loop conditions have to test. Which construct meets that requirement directly?
a) A continue in the inner loop
b) A flag set in the inner loop and tested by both loop conditions
c) A goto to a label placed immediately before the clean-up step
d) A break in the inner loop
02. A file-scope object is defined as static int cache; in one source file of a multi-file program. What does the static keyword change about that object?
a) The object is placed in the same block of memory as the automatic objects of main
b) The name is given internal linkage, so other translation units cannot refer to it
c) The object gains static storage duration it would not otherwise have
d) The object may no longer be modified after it has been initialised
03. Which statements about functions in C are correct?
(Choose two.)
a) The number of arguments in a call may differ from the number of parameters, provided their types match
b) A function whose parameter list is void may still be called with arguments, which are then discarded
c) A parameter declared without a storage-class specifier has static storage duration, so it keeps its value between calls
d) A parameter may carry the same name as a file-scope object, and inside the function the parameter hides it
e) A function may be called before its definition appears, provided a declaration is in scope at the call
04. A programmer needs a file-scope name for an internal buffer and is choosing between four spellings, all of which the compiler accepts. Which one is a legal identifier that a program should nevertheless avoid, because names of that shape are reserved to the implementation?
a) buffer_
b) buffer2
c) _Buffer
d) myBuffer
05. The lines below appear inside main() of a complete program that includes <stdio.h>.
int a[4] = {5, 6, 7, 8};
printf("%d %d %d", a[2], *(a + 2), 2[a]);
What does the fragment write to standard output?
a) 7 7 7
b) 5 7 7
c) 7 8 7
d) 7 7 5
06. A function must add up all elements of an array. Two candidate loops are written, with n holding the element count.
for (i = 0; i <= n; i++) sum += a[i];
for (i = 0; i < n; i++) sum += a[i];
Which assessment of the two loops is correct?
a) The first reads one element past the end of the array, which is undefined; the second is correct
b) The first is correct only when n holds the highest valid index rather than the element count
c) The first is correct; the second omits the last element
d) Both are undefined, because an index computed from a loop counter is not a constant expression
07. Which statements about operator precedence and associativity in C are correct?
(Choose two.)
a) a << 1 + 2 shifts a left by one and then adds two
b) Precedence decides the order in which the operands of an expression are evaluated
c) Assignment groups right to left, so a = b = 0 stores 0 in b and then in a
d) Parentheses raise the precedence of the operators written inside them
e) The comma operator has the lowest precedence of any operator, so a = b, c assigns b to a before yielding c
08. Inside a function body a programmer writes extern long counter; and then reads and writes counter. What must also be true for the program to link successfully?
a) Some translation unit must contain a definition of counter with external linkage
b) The same function must also contain a plain long counter;
c) The declaration must appear at file scope rather than inside a block
d) The object must be given an initialiser at the point of the extern declaration
09. A program manipulates an int object x that is known to hold a positive value. Which statements about the expressions below are correct?
(Choose two.)
a) ~x yields the same value as -x
b) x & (x - 1) yields x with its lowest set bit cleared
c) x >> 1 divides by two and rounds away from zero
d) x ^ x yields zero for every value x can hold
e) x | ~x yields 1, because every bit position is covered
10. An array is declared as int a[10]; and a loop needs a pointer that marks the position just past the last element, so the loop can stop when it reaches that marker. Which statement about int *end = a + 10; is correct?
a) Compilation fails
b) Both forming and dereferencing end are well defined
c) Forming and comparing end is well defined, but dereferencing it is not
d) Forming end is already undefined, so the loop must stop at a + 9