The difference between initialization and assignment
In C + +, the variable initialization and assignment operators are two completely different concepts.
Initialization is not an assignment, the meaning of initialization is to assign an initial value when creating a variable allocation storage space, and the meaning of the assignment is to erase the current value of the memory space and replace it with a new value.
List initialization in C + +
int number1 = 1
int number2 (1)
int Number3 {1}
int number4 = {1}
As a new standard for c++11, curly braces are used to initialize variables for full application, which is called List initialization (listing initialization)
List initialization features: Compiler error when initializing with list and the initial value is at risk of information loss
int Num{1}//correct
int num2{1.1}//Error
int NUM3 = 1.1//correct
Default initialization
A built-in type variable defined in the body of any function is initialized to 0, and the built-in type variable defined inside the function body will not be initialized, this value is undefined, it is an indeterminate value, using the value of an uninitialized variable is a wrong way of programming, and it is difficult to hang, It is recommended that variables be initialized when each built-in type variable is defined.
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------
C + + variable initialization issues