C language: differences between global variables and local variables
Static global variables: Program: # include <stdio. h> # include <stdlib. h> void fun () // a function defined by fun {int I = 0; static int num = 0; for (I = 0; I <10; I ++) {num = 0; // once the for loop is entered, the global variable is assigned 0 num ++; printf ("% d", num) ;}} int main () {fun (); system ("pause"); return 0 ;}result: 1 1 1 1 1 1 1 1 press any key to continue... local variable: Program: # include <stdio. h> # include <stdlib. h> void fun () // a function defined by fun {int I = 0; for (I = 0; I <10; I ++) {int num = 0; // local variable, acting only within the function num ++; printf ("% d", num) ;}} int main () {fun (); system ("pause"); return 0;} result: 1 1 1 1 1 1 1 1 1 1 1 please press any key to continue... static variable initialization: Program: # include <stdio. h> # include <stdlib. h> void fun () // a function defined by fun {int I = 0; for (I = 0; I <10; I ++) {static int num = 0; // static variable, equivalent to executing num ++; printf ("% d", num) ;}} int main () only once during initialization () {fun (); system ("pause"); return 0 ;}result: 1 2 3 4 5 6 7 8 9 10 press any key to continue...