What this C++ global-variable scoping question tests
This is a hard C++ language-knowledge question that probes your understanding of global scope, variable shadowing, and name resolution in the presence of multiple declarations. It rewards precise knowledge of how the C++ linker and compiler resolve symbols across translation units.
To answer correctly, you need to trace how a global variable declared in one scope interacts with identically-named entities in different scopes, and understand the rules that determine which symbol is actually used at runtime. The question tests whether you can reason about linkage, visibility, and the order in which declarations and definitions are processed—skills essential for writing correct C++ in large codebases and for diagnosing linker errors.
- External vs. internal linkage and the
static and extern keywords - Variable shadowing and name hiding in nested scopes
- One Definition Rule (ODR) and symbol resolution
- Namespace scope vs. block scope