Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Introduced in C++11, auto tells the compiler to automatically deduce the data type of a variable from its initializer.
auto x = 10; // x is int auto y = 3.14; // y is double auto s = "Hello"; // s is const char* // Very useful for complex types: auto it = myMap.begin();
Types are still determined at compile time. C++ remains a statically typed language.
You cannot use auto without an initial value. auto x; is an error.
Use auto when the type is obvious or extremely long (like iterators). Avoid it for simple types if it makes the code less readable.