1.static:修饰静态的局部变量。
![](https://img-blog.csdnimg.cn/img_convert/283c818e913e03d15c1c922c260ba551.png)
(1)static修饰局部变量时,局部变量的生命周期边长,改变了变量的作用域。
如下图在int a=0;增加static int a=0;后,输出结果由1,1,1,1,1变为了1,2,3,4,5。
![](https://img-blog.csdnimg.cn/img_convert/8a0d7bce2efdbd289279315bae0653d9.png)
(2)此时使用的static可以理解为下图程序中int a=0;在程序中所发挥的作用。
![](https://img-blog.csdnimg.cn/img_convert/6c1d24410b28245b68d2f19f2e59361b.png)
2.extern:声明外部符号。(直接调用外部文件变量或函数)
用法:如下图中使用extern调用add.c文件中的语句。
![](https://img-blog.csdnimg.cn/img_convert/e0b4b1b33ebf7ebcdc5a00b4d0a45dfc.png)
(1)使用extern修饰函数时,与变量类似。
![](https://img-blog.csdnimg.cn/img_convert/994cfa61ddf2b40378975d31d73304fe.png)
(2)static修饰让静态的全局变量只能在自己所在的源文件内部使用,出了源文件就无法使用。
如下图中增加了staic int g_cal=2022;
![](https://img-blog.csdnimg.cn/img_convert/6b90601ef328b0f369d417a12676bc65.png)
(3)static修饰函数改变了函数的链接属性。(外部链接属性→内部链接属性)
如下图,增加static后程序报错。
![](https://img-blog.csdnimg.cn/img_convert/7c2d0d8106327d8a0c29086bf1e874e7.png)