Difficulty: Easy
Correct Answer: The program will print the output 2 3 4 .
Explanation:
Introduction / Context:
This question checks the effect of pre-increment on constructor parameters versus post-increment when streaming values. Understanding sequence and timing of increments is key.
Given Data / Assumptions:
x=++xx, y=++yy, z=++zz.x++, y++, z++.
Concept / Approach:
Pre-increment increments first, then yields the incremented value for assignment. Post-increment yields the current value for output, then increments afterward.
Step-by-Step Solution:
After construction: x=2, y=3, z=4.Streaming with post-increment prints 2, 3, 4 in order.After printing, the internal values become 3, 4, 5 (not shown).
Verification / Alternative check:
Add a second call to Show(); it will then print 3 4 5 because of the prior post-increments.
Why Other Options Are Wrong:
Option A ignores the constructor’s pre-increment. Option C reflects the internal state after a hypothetical second print. Option D is incorrect because the code is valid C++.
Common Pitfalls:
Mixing up pre- and post-increment semantics and assuming both behave identically in assignments and outputs.
Final Answer:
The program will print the output 2 3 4 .
Discussion & Comments