What this C++ code-reading question tests
This is an easy C++ question that appears in interviews at firms like Microsoft. It asks you to trace the execution of a code snippet and predict its output—a fundamental skill that reveals whether you understand the language's semantics at a concrete level.
Questions of this type probe your grasp of scoping rules, variable lifetimes, and the order in which statements execute. Even on "easy" difficulty, subtle language features can hide in plain sight. The goal is not just to guess an answer, but to reason through the code path systematically and explain what happens at each step.
- Variable scope and shadowing
- Control flow and statement execution order
- Output stream behaviour
- Lifetime and visibility of identifiers