What is the difference between auto and decltype, and what is decltype(auto)?

Last updated 21 June 2026

  • auto deduces like template deduction, stripping top-level const and references (use auto& to keep them).

  • decltype(expr) yields the exact type including references. A parenthesized lvalue like decltype((x)) yields a reference.

  • decltype(auto) deduces from the initializer using decltype rules, mainly for forwarding return types that must preserve references.

  • https://medium.com/@hunkcool1991/auto-type-deduction-decltype-explained-writing-cleaner-code-without-losing-type-safety-26cff3e55d52
All C++ interview questions