के सभी प्रकाशन Innovative Thinkers . पुणे , भारत
auto in C++ is explained in few simple steps:
The keyword auto in C++ (Type Inference) refers to automatic deduction of the data type. Deduction happens at compile time.
In C++11, the meaning of the auto keyword has changed, consider the following statement:
double d = 5.0;
Do you know what is type inference (or type deduction) in C++ 11?
Starting with C++11, When initializing a variable, the auto keyword can be used in place of the variable type to tell the compiler to infer the variable’s type from the initializer’s type.
auto d = 5.0; // 5.0 is a double literal, so d will be type double
auto i = 1 + 2; // 1 + 2 evaluates to an integer, so 'i' will be type int
auto type deduction even works with the return values from functions:
int add(int x, int y)
return x + y;
auto sum = add(5, 6); // add() returns an int, so sum will be type int