What this C++ type-deduction interview question tests
This is a medium-difficulty C++ language-knowledge question that probes your understanding of how the auto keyword interacts with braced initializer syntax. It rewards precision about the rules the compiler applies when inferring types in modern C++.
The question hinges on recognizing that braced initializers have special deduction rules. Candidates need to know when auto deduces to a concrete type versus when it deduces to a container type like std::initializer_list, and how the presence or absence of braces changes that outcome. This matters in real codebases because a small syntactic choice can silently change your variable's type and behaviour.
- Type deduction rules for
auto in C++11 and later - Braced initializer semantics and
std::initializer_list - Difference between direct and copy initialization with braces