It is not uncommon to want to store the value of an expression in a variable. To
Declare the variable, we have to know the type of the. When we write a
program, it can be surprisingly difficult-and sometimes even impossible-to
Determine the type of an expression. Under the new standard, we can let the compiler
The type for us by using the auto type specifier. Unlike type specifiers, such
As double, that's name a specific type, auto tells the compiler to deduce the type
From the initializer.
Auto Item=val1+val2;
The following statement is incorrect:
Auto a=0,b=3.14;//variable A is inconsistent with type B
Auto requires consistent variable types defined within the same row
Auto usually ignores the top-level const without ignoring the underlying const, such as:
Const int ci=i,&cr=ci;auto b=ci; // The top-level const is ignored by auto C=CR; // CR is the alias of the top-level CONSTCI Auto e=&ci; // e is a pointer to a const object, and E is the underlying const
If you want the auto type to have a top-level const property, you need to declare it:
const Auto b=ci; // at this point B has the top-level const property
Auto type Use