When when to be!
Time is really good fast, C language has learned, began to learn C + +, blog did not insist on writing, new stage New start, hope to write on time!
Scope: You cannot declare two variables of the same name under the same scope
1#include <iostream>2 using namespacestd;3 intAge = -;//comment out this line4 namespace Person5 {6 intAge = $;7 }8 namespaceBird9 {Ten intAge = -; One intSex =101; A } - using namespaceBird; - intMain () the { -cout<<::age<<endl;//view this row change global variable precedence high -cout<<person::age<<Endl; -cout<<bird::age<<Endl; +cout<<::sex<<Endl; -}
1#include <iostream>2 using namespacestd;3 intMain ()4 {5 int*p =New int;6*p =Ten;7cout<<*p<<Endl;8 Deletep;9p =0;Ten One int*arr =New int[Ten]; Aarr[0] =0; -arr[1] =1; -cout<<arr[0]<<" "<<arr[1]<<Endl; thecout<<arr<<Endl; - Delete[] arr;//Delete array to add [] - //cout<<arr<<endl; - //the pointer also points to the address after the delete, but the space is no longer mine, do not manipulate it! +arr =0; - + int*a =New int(Ten);//Initializes an int that is a pointer to ten Acout<<*a<<Endl; at DeleteA; -A =0; -}
- Default function parameters
1#include <iostream>2 using namespacestd;3 4 voidShow (intAintBintc =2,intD =3);5 intMain ()6 {7Show ( -, $);8 intarr[Ten] = {0,1,2,3,4,5,6,7,8,9};9 }Ten //You can no longer add parameters to a function implementation, or duplicate definitions if they already exist in the function declaration, and if they are not, they are malformed. One voidShow (intAintBintCintd) A { -cout << a <<" "<< b <<Endl; -cout << C <<" "<< D <<Endl; the}
1 for (Auto I:arr) // Auto recognizes types in arr 2 {3 " " ; 4 }
Function name is the same, function parameter number or type is different
C + + basic syntax