Talking deeply about auto variable
1. There is a keyword in auto,c +, but the meaning of the two is quite different.
2. The variable defined by auto in C codes + automatically matches the type of the value on the right of the assignment symbol, with the function of automatically matching type, while auto in c language only declares a variable as an automatic type, indicating that the code block lifetime of this variable and allocation on the stack, and can not be used to define variables.
3. Auto can play the role of generics in clocked +. No matter what type you pass to me, I can recognize it and use this variable by type.
4. Let's look at the cpp test code.
1 # include 2 3 using namespace std; 4 5 / * 6 automatic variable: automatic matching type 7 auto num = pc; generic incoming interface 8 decltype (num) anum;/ generic backup interface 9 * / 10 11 void main () 12 {13 14 auto a = 10 auto auto / parsing a to integer variable 15 auto b = 10.1 auto / parsing b to floating point variable 16 17 int array [10]; 18 int I = 0 19 for (auto arr: array) / / enhanced for cycle 20 {21 arr = iDeposition22 cout