What this C++ code-output question tests
This is a medium-difficulty question that probes your understanding of copy semantics in C++—specifically, how the compiler handles object construction, assignment, and implicit copying in different contexts. It rewards precise knowledge of when copy constructors and assignment operators are invoked, and what happens when they are not explicitly defined.
To answer correctly, you need to trace the execution path through the code, identify which operations trigger copies, and predict the exact output (or lack thereof). Many candidates underestimate subtle interactions between default constructors, copy constructors, and the order of side effects, especially when member variables or temporary objects are involved.
- Implicit vs. explicit copy construction
- Copy elision and return-value optimization
- Default-generated vs. user-defined copy semantics
- Order of evaluation and constructor side effects