1. Built type default initialization
If there is no built-in types are displayed initialized, it will be the compiler default initialization. According to the type of the variable initialization ① ② different types of position variables to determine the value after initialization. But if the built-in types inside the function body, it will not be initialized - that is undefined, while operating an undefined variable can cause errors. As will therewith, string type will provide a default initialization, so the line 21 by operation on the variable str.
. 1 #include <the iostream> 2 #include < String > . 3 the using namespace STD; . 4 . 5 int I; // definition function in vitro, it will be initialized to 0 . 6 static int K; . 7 . 8 int main () . 9 { 10 COUT I << << endl; . 11 COUT << K << endl; 12 is 13 is int j; 14 // I = j; // illegal, j defined as 15 // COUT << j << endl; // same illegal 16 . 17 static int G; 18 is COUT G << << endl; // valid . 19 20 is String STR, ST ( " 23 is " ); 21 is ST = STR; // legal, string class provides a suitable default value 22 }