What this C++ language-knowledge question tests
This is a medium-difficulty question that probes your understanding of C++ scoping rules, variable shadowing, and how the compiler resolves name lookups in nested contexts. It's the kind of question trading firms use to separate candidates who have read the language specification from those who rely on intuition alone.
To answer correctly, you need to trace through the code mentally, paying careful attention to which declarations are in scope at each point and how inner scopes can mask outer ones. The question rewards precision: a small oversight in scope analysis leads to the wrong answer. Interviewers value candidates who can explain their reasoning step-by-step rather than guess.
- Scope resolution and name lookup order
- Variable shadowing in nested blocks
- Lifetime and visibility of automatic variables