Difficulty: Easy
Correct Answer: The program will print the output 50 49.
Explanation:
Introduction / Context:
The item checks precise evaluation order when printing a referenced variable and then applying a pre-decrement to that same aliased object. Understanding that y is an alias of x is critical here.
Given Data / Assumptions:
Concept / Approach:
In the chained output, operators are sequenced left-to-right. First, the current value of x (50) is sent to the stream. Next, --y is evaluated, which decrements the aliased object from 50 to 49, and that value (49) is inserted. Although x becomes 49 due to the aliasing, x was already printed as 50 prior to the decrement.
Step-by-Step Solution:
Verification / Alternative check:
Replace --y with y-- and observe a different result (50 50) because y-- prints the old value before decrement; here we use pre-decrement.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming both outputs reflect the decremented value; confusing pre- and post-decrement semantics.
Final Answer:
The program will print the output 50 49.
Discussion & Comments