What this C++ code-tracing question tests
This is a medium-difficulty code-tracing question that asks you to predict the output of a C++ snippet. It rewards careful attention to language semantics, object lifetime, and scope—topics that matter deeply in production systems where silent failures or undefined behaviour can be costly.
To solve problems like this, you need to mentally execute the code step by step, tracking when objects are constructed and destroyed, how scope affects visibility, and what side effects (if any) actually occur. The question often hinges on understanding C++ rules around temporary objects, scope exit, and resource management.
- Object lifetime and destruction order
- Scope and visibility rules
- Constructor and destructor invocation
- Temporary object semantics