Difficulty: Medium
Correct Answer: 1 0 4
Explanation:
Introduction / Context:
This question checks evaluation order and reference binding in C++. The constructor of CuriousTab prints its three integer data members immediately. The main function passes references formed via pre-increment and pre-decrement and computes a third argument using unary minus on a negative operand.
Given Data / Assumptions:
Concept / Approach:
Pre-increment (++a) increments then yields the new value; pre-decrement (--b) decrements then yields the new value. A reference binds to the resulting lvalue, so later reads observe the updated underlying variable. The expression “- -c” is the negation of a negation, effectively +c.
Step-by-Step Solution:
1) ++a: a becomes 1, x refers to a (value 1). 2) --b: b becomes 0, y refers to b (value 0). 3) z = c + b - -c = 2 + 0 + 2 = 4. 4) Constructor receives (1, 0, 4) and immediately prints “1 0 4”.
Verification / Alternative check:
Replace “- -c” with “+c” and you still get 4; the output remains unchanged.
Why Other Options Are Wrong:
“1 0 3” miscomputes z; “1 1 3/4” wrongly treats y as 1; “Compile-time error” is incorrect because the code is valid with old-style headers.
Common Pitfalls:
Forgetting that references alias variables after the increment/decrement, and misreading “- -c”.
Final Answer:
1 0 4
Discussion & Comments