"Local Variables" (local variable)
1, defined in a function, the scope is only within the scope of this function.
2, defined in a compound statement, the scope is only in the compound statement.
"Global Variables" (Globals variable)
#定义在函数之外, the scope begins with the definition of the variable to the end of the source file.
"Local variable with the same name"
#不同作用域的同名局部变量, do not interfere with each other, in memory is in different storage space.
"Local variable has the same name as global variable"
#当局部变量与全局变量重名时, global variables are masked due to the local precedence principle .
"Disadvantages of global variables" ———— "high cohesion, low coupling"
Global variables can reduce the readability of the program.
The space utilization efficiency of global variables is reduced,
Global variables can reduce the generality of the program,
#####################################################
Storage categories for data
"Automatic variable" (auto variable)
#auto是局部变量的默认存储类别,
The variable automatically allocates space, and automatically frees the memory space after the program finishes executing.
"Register variable" (register variable)
"External variables" (extern variable)
"Static variables" (static variable) ·
#静态变量 can only be initialized once
"Use scenario" when you need to use the value of the last called function, you can use the static type variable.
Global, local variables, storage categories for data