Static and extern, staticextern
Static and extern modifier local variables
Static modifier local variables:
Purpose: 1) the scope of static variables will be extended.
2) statements defining static variables are executed only once.
Extern cannot modify local variables
Void test (int num) {static int n = 0; printf ("% d", n); n ++;} int main () {test (); // The output result is 0 test (); // The output result is 1 test (); // The output result is 2}
Static effect on global variables (internal variables)
Static global variable, indicating that the global variable can only be used in the current file, but not in other files
Variables with the same name can be declared using static in different files
Effect of extern on global variables
The global variable modified by extern indicates that the current variable can be used in this file, or
Use other files
The global variables declared by extern cannot have the same name in different files (the two files must have an inclusion relationship)
Functions of static and extern
The static modifier is an internal function (which can only be used in the defined file)
The function declared by extern can be used in the definition file or in other files.