#include int globle_init=100;//全局初始化变量 staticint static_globle_init=100;//static修饰的全局初始化变量 int globle_unit;//全局未初始化变量 voidf1(){staticint static_init=100;//static修饰的局部初始化变量staticint static_unit;//static修饰的局部未初始化变量int local_var=100;// 局部初始化变量static_init++;local_var++;printf("The value of static_unit is %d\n",static_unit);printf("The value of static_init is %d\n",static_init);printf("The value of local_var is %d\n",local_var);printf("================================\n"); } voidf2(){globle_unit=100; } intmain(){f1();f1();printf("The value of globle_unit is %d\n",globle_unit);f2();printf("The value of globle_unit is %d\n",globle_unit);return0; }
运行结果如下:
The value of static_unit is 0 The value of static_init is 101 The value of local_var is 101 ================================ The value of static_unit is 0 The value of static_init is 102 The value of local_var is 101 ================================ The value of globle_unit is 0 The value of globle_unit is 100