Refer to the exhibit. What is the output?
Correct. a++ gives 5, ++a gives 7.
Why this answer
The exhibit shows code that initializes an integer array with values 1 through 5. The enhanced for loop iterates over each element, adding each value to the variable 'sum' (starting at 0). After summing all five elements (1+2+3+4+5), sum equals 15.
The code then prints the value of sum minus 3, which is 12. Therefore, option C is correct.
Exam trap
The trap here is that candidates may misread the code and think the loop only sums a subset of elements, or they may incorrectly compute the sum (e.g., forgetting to include the last element) or misapply the subtraction, leading to a wrong answer like 10, 11, or 13.
How to eliminate wrong answers
Option A is wrong because 10 would be the result if the loop only summed the first four elements (1+2+3+4) and then subtracted 0, or if a different arithmetic error occurred. Option B is wrong because 13 would be the result if the sum was 16 and then 3 was subtracted, or if the loop incorrectly skipped an element or added an extra value. Option D is wrong because 11 would be the result if the sum was 14 (e.g., missing one element like 5) and then 3 was subtracted, or if the subtraction was misapplied.