
上QQ阅读APP看书,第一时间看更新
7.6.5 static关键字用法总结
本节讲解了static关键字的几种用法,请务必牢记,总结一下。
(1)函数内部在定义一个局部变量时,在前面使用static关键字,则该变量会保存在静态存储区,在编译的时候被初始化,如果不给初始值,它的值会被初始化为0,并且,下次调用该函数时该变量保持上次离开该函数时的值。例如:

(2)在定义全局变量时前面使用static关键字,那么该全局变量只能在本文件中使用,无法在其他文件中被引用(使用)。例如:

(3)在函数定义之前增加static,那么该函数只能在本源程序文件中调用,无法在其他源程序文件中调用。例如:
