As described in the 40th page of C + + primer 5th, if you define a variable without specifying an initial value, the variable is initialized by default, and the variable is given a "default."
Depending on the position defined by the variable, there are two situations:
1. Variables defined outside of any function body are initialized to 0.
2. The built-in variables defined inside the function body will not be initialized.
Here are two things that should be very clear, but when I learned about classes, I still had questions about how member variables in the class were initialized.
In writing the exercises, I studied it clearly.
The default initialization of a member variable within a class is related to the location of the object defined by the class, in two cases:
1. An object defined in a class other than the body of any function whose member variable is initialized to 0.
2. The object of the class defined within the function body, will not be initialized, the value is random.
Looking back at the default initialization of variable definitions, you can see that the case of member variables in the class is consistent with ordinary variables.
Explore C + + default initialization