When you define a variable without initialization, some variables are initialized.
Some variables: global variables, static variable namespaces (all of which are variables of built-in types). Local non-static variables are not initialized as non-static variables inside the function.
1 namespaceMySpace2 {3 intmInt;4 }5 6 intMain ()7 {8 //mySpace mint:09cout <<"mySpace mInt:"<< Myspace::mint <<Endl;Ten return 0; One}
For non-built-in type variables, such as classes are initialized by constructor functions. When a class has a default constructor, the variable is not initialized, and the system may automatically be initialized with the default constructor (the default constructor is not a parameter), and the other point is that the system may be using the default constructor because the default constructor is not initialized when it is inaccessible: the default constructor is Private
1 classTmyclass2 {3 Public:4 //...5 Private:6Tmyclass (): _int (0) {cout <<"Tmyclass default constructor called"<<Endl;}7 Private:8 int_int;9 };Ten intMain () One { ATmyclass T1;//Error -System"Pause"); - return 0; the}
It is said that variable initialization also has explicit and implicit points when the constructor of the learning class encounters
C + + variable initialization