Difficulty: Easy
Correct Answer: 11 21
Explanation:
Introduction / Context:
This question checks understanding of references passed to a constructor and side effects on the original variables a and b when they are modified by reference within the constructor body.
Given Data / Assumptions:
Concept / Approach:
When int& parameters are used, the constructor receives aliases to a and b. Any modification (like ++) directly changes the original variables. Therefore, after construction, a == 11 and b == 21, and cout prints those updated values.
Step-by-Step Solution:
Verification / Alternative check:
Changing the constructor to take values (int x, int y) would not change a and b; the program would then print 10 20. References are the key to mutation here.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing pass-by-value with pass-by-reference; expecting constructor parameters to be copies by default.
Final Answer:
11 21
Discussion & Comments