Summary of internal variables, static internal variables, static external variables, and external variables:
Variables have two attributes: scope and lifecycle.
An internal variable is a variable defined in a function (or statement block,It is stored on the stack,The bucket is allocated only when the function is run.The function scope is in this function (or statement block). The lifecycle ends from the definition of this variable to the end of this function (or statement block.
Static internal variables, static variables defined in the function,Not Stored on stacks,Allocate storage space during compilation. The function is used in this function,But the lifecycle is fromProgramExecution starts until the program ends.,Each time you enter this function, the value of the static variable is the previous value.
Static external variables are defined as static variables outside all statement blocks,Not Stored on stacks,Allocate storage space during compilation. Static external variables are used to restrict the variable to be valid only in this file. If a variable with the same name is defined in other files, the compiler treats it as another variable.
External variables are defined outside all statement blocks,Not Stored on stacks,Allocate storage space during compilation. The function scope is from the definition to the end of this file. If the previous function needs to use this variable, you needExtern xxxThis variable can be used only when it is declared. The external variable range can be extended to other files, that is, other files can also use this variable, but before using this variable, you mustExtern
XxxDeclare the variable to use it.