What is the difference between static global variables and common global variables? What is the difference between static local variables and common local variables? What is the difference between a static function and a common function?
A. The description of global variables (external variables) is preceded by static to form a static global variable. Global variables are static storage, and static global variables are also static storage. The two are not different in storage methods. The difference between the two lies in that the scope of non-static global variables is the entire source program. When a source program is composed of multiple source files, non-static global variables are valid in each source file. The static global variable limits its scope, that is, it is valid only in the source file defining the variable, and cannot be used in other source files of the same source program. Because the scope of static global variables is limited to one source file, they can only be shared by functions in the source file. Therefore, errors in other source files can be avoided.
From the above analysis, we can see that after a local variable is changed to a static variable, its storage mode is changed, that is, its survival time is changed. After changing a global variable to a static variable, it changes its scope and limits its scope of use.
Static functions have different scopes than normal functions. Only in this file. Only functions used in the current source file should be declared as internal functions (static). Internal functions should be described and defined in the current source file. For functions that can be used outside the current source file, it should be described in a header file that the source file to use these functions must contain this header file.
What is the difference between static global variables and common global variables? STATIC global variables are only made once to prevent being referenced in other file units;
What is the difference between static local variables and common local variables: static local variables are initialized only once, and the next time is based on the previous result value;
What is the difference between a static function and a common function: a static function has only one copy in the memory, and a normal function maintains one copy in each call.
Local variables of the program exist in (stack), global variables exist in (static zone), and dynamic application data exist in (HEAP.