static修饰
1.局部变量 2.全局变量 3.函数
void test()
{
static int a = 1;
a++;
printf("%d", a);
}
int main()
{
int i = 0;
while (i < 10) {
test();
i++;
}
return 0;
}
static 修饰局部变量,改变局部变量的生命周期。 使局部变量不被销毁
本质上改变了变量的存储类型
static 修饰全局变量,该变量只能在自己的源文件使用。
static 修饰函数,使得函数只能在自己的源文件内使用。
不能在其他源文件内使用