auto

Applies to: cpp

auto lets the compiler deduce a variable's type from its initializer, cutting verbose type names while staying statically typed. Especially handy with iterators and templates.

auto it = v.begin();        // type deduced
for (auto& x : v) x *= 2;   // x is the element type, by reference

See also: data-type, iterator, range-based-for