auto

Instructs the compiler to automatically deduce the type of a variable from its initializer expression.

Syntax

cpp
auto variable = expression;

Example

cpp
auto x = 42;            // int
auto pi = 3.14;         // double
auto s = string("hi");  // string

vector<int> v = {1, 2, 3};
for (auto& elem : v) elem *= 2;

auto it = v.begin();    // iterator type