2022.3.5 static关键字的运用(静态)
#include <stdio.h>
void test()
{
static int a=1;//没加static时int的值自动销毁,没有保存
a++;
printf("%d\n",a);//结果为2,3,4,5,6,
}
int main()
{
int i=0;
while(i<5)
{
test();
i++;
}
return 0;
}//static修饰局部变量,局部变量的生命周期变长
//static修饰全局变量,改变了变量的作用域--让静态的全局变量只能在自己所在的源文
//件只能在源文件内部使用 extern无法使用
//一般extern声明一下是可以的,运用了外部链接属性
//static把外部链接属性变成内部链接属性