C language, global variables, local variables, external functions, internal functions, stasic and extern,
Local variable
Definition: variables defined within a code block
Scope: starts from the line that defines the variable until the end of the code block.
Lifecycle: the bucket is allocated from the row where the variable is defined. After the code block ends, it is recycled.
No Default Initial Value
Global Variables
Definition: variables defined outside the Function
Scope: starts from the line that defines the variable and ends with the end of the file (can be shared by all subsequent functions)
Life cycle: when a program is started, it will allocate storage space and the program will be destroyed only when it exits.
The default value is 0.
Global variables include external variables and internal variables.
External variables: Defined variables can be accessed by this file and other files. By default, all global variables are external variables.
Internal variables: Defined variables can only be accessed by this file, but cannot be accessed by other files
Internal function: the defined function can only be referenced in this document. Other files cannot be accessed.
Allow different files to have internal functions with the same name
External function: the defined function can be accessed by other files.
By default, all functions are external functions.
External functions with the same name are not allowed.
Static and extern
Valid for both functions and variables
Static defines and declares an internal function and defines an internal variable.
Static local variables are modified to prolong the life cycle of local variables. After the program ends, the local variables are destroyed and the scope of local variables is not changed.
Extern defines and declares an external function and declares an external variable.