What this C++ initialization interview question tests
This is a medium-difficulty C++ language-knowledge question that probes your understanding of how the language initializes variables in different contexts. It rewards precise knowledge of initialization semantics over guesswork, and is the kind of question interviewers ask to separate candidates who have read the standard from those who rely on intuition.
To answer correctly, you need to understand the distinctions between default initialization, value initialization, aggregate initialization, and other initialization forms—and how they behave differently depending on whether a variable is local, global, a class member, or dynamically allocated. The "trick" lies in recognizing which initialization rule applies in the specific code context presented.
- Default vs. value initialization semantics
- Zero-initialization and indeterminate values
- Brace initialization and uniform initialization syntax
- Storage duration and initialization order