Understanding language-specific zero-initialization in C++
This is a medium-difficulty C++ language-knowledge question that tests whether you understand how different variable types are initialized—or not initialized—in C++. It's the kind of detail that separates candidates who have read the standard from those who rely on intuition, and it often surfaces in code-review and debugging rounds.
The question hinges on the distinction between uninitialized variables, zero-initialization, and default-initialization across different scopes and types. Getting this right requires knowing the exact rules that govern what happens when a variable is declared but no explicit initializer is provided, and how those rules differ for primitives, objects, and static storage duration.
- Automatic vs. static storage duration
- Default-initialization and value-initialization semantics
- Uninitialized local variables and undefined behaviour
- Zero-initialization rules for different types