0Pricing
C++ Academy · Lesson

auto decltype and Type Deduction

Let the compiler deduce types with auto and decltype for cleaner code.

Type Deduction in Modern C++

Since C++11 the compiler can deduce types in many places. This makes code shorter and less error prone — when used wisely.

The auto Keyword

auto deduces the type from the initializer at compile time. The variable still has a fixed, statically-known type.

auto i = 42;          // int
auto d = 3.14;        // double
auto s = "hello";     // const char*
auto v = std::vector<int>{1,2,3};   // std::vector<int>

All lessons in this course

  1. auto decltype and Type Deduction
  2. Range-based for nullptr and enum class
  3. Lambda Expressions Capture Mutable Generic
  4. Structured Bindings and if-init C++17
← Back to C++ Academy