What this C++ type-deduction interview question tests
This is an easy C++ question that probes your understanding of type deduction rules in modern C++ (C++17 and beyond). It appears frequently in coding interviews because getting types right is foundational to writing correct, efficient code — and because type deduction can be surprisingly subtle in practice.
To solve questions like this, you need to mentally trace through the compiler's type-deduction algorithm: how does the declared type of a variable interact with the type of its initializer? What role do qualifiers, references, and template argument deduction play? The question rewards precision and systematic thinking over guesswork.
- Template argument deduction rules
- Qualifiers (const, volatile, reference) and their handling during deduction
- How initializer expressions affect the final type