Data Type Auto

suggest change

This example shows the basic type inferences the compiler can perform.

auto a = 1;        //    a = int
auto b = 2u;       //    b = unsigned int
auto c = &a;       //    c = int*
const auto  d = c; //    d = const int*
const auto& e = b; //    e = const unsigned int& 

auto x = a + b     //    x = int, #compiler warning unsigned and signed

auto v = std::vector<int>;    //    v = std::vector<int>

However, the auto keyword does not always perform the expected type inference without additional hints for & or const or constexpr

//    y = unsigned int, 
//    note that y does not infer as const unsigned int&
//    The compiler would have generated a copy instead of a reference value to e or b
auto y = e;

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Type inference:
* Data Type Auto

Table Of Contents
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
122 Type inference
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype