Understanding decltype behaviour in C++
This is a hard C++ language-knowledge question that tests your grasp of type deduction rules, particularly how decltype handles expressions and references. It rewards careful reading of the C++ standard over intuition, since decltype's behaviour often surprises even experienced developers.
To solve problems like this, you need to distinguish between what decltype infers from an expression versus what type a variable actually holds, and to recognize edge cases where parentheses, lvalue/rvalue status, and expression context change the deduced type. Interviewers use these questions to identify candidates who reason rigorously about type systems rather than relying on guesswork.
- Expression vs. entity decltype rules
- Lvalue and rvalue reference deduction
- Parenthesization and its effect on type inference