A static local variable
1 storage space allocation scope lifetime
Static is allocated in the static storage area, and the scope is limited to the internal function that declares the variable. InProgram
The entire running period is not released, and the lifetime runs throughout the entire process of running the program.
AutoThe type is distributed on the stack and belongs to the dynamic storage class, which occupies the dynamic storage space. The scope is limited to the function that declares the variable. The function is automatically released after the function call ends. The lifetime is within the function that declares the variable.
2Processing Method when initial values are assigned
Static static local variables assign initial values at compilation, that is, only the initial values are assigned once;
Auto auto variable assigns an initial value when the function is called. Every time the assign function is called, the initial value is re-assigned, which is equivalent to executing a value assignment statement.
3. Processing Method without initial values
If the initial value is not assigned when defining a local variable:
Static local variables. The initial value 0 (For numeric variables) or null characters (for character variables) are automatically assigned during compilation ).
Auto automatic variable. If no initial value is assigned, its value is an uncertain value.
2. Static external global variables
InCLanguageStaticIt is also used to declare static external global variables, so the scope of this global variable is restricted within this file.
If the function before the definition point wants to call this variable, you should use the keyword before reference.ExternMake an "external variable Declaration" for this variable ".
This variable is an external variable that has been defined. With this declaration, you can legally use this external variable from the "Declaration.
If the declared global variables do not want to be accessed and used by other files, add the keyword static before the declaration.
Three static external functions
The function in C language is global by default. If an external file is to be referenced, you can add an extern. If you do not want to be referenced, use static modification.