C语言static用法之函数内部static变量

C语言static用法之函数内部static变量,第1张

Static local variables

When a variable in a function is static, the variable preserves its value between function calls.

#include 
#include 

void fun2() {
	static int count = 0;
	count++;
	printf("%d\n", count);

}

void fun() {
	int count = 0;
	count++;
	printf("%d\n", count);

}

int main() {
	fun();
	fun();
	fun();

	fun2();
	fun2();
	fun2();
	return EXIT_SUCCESS;
}


参考: https://linuxhint.com/static_c/

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/3002542.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-09-27
下一篇 2022-09-27

发表评论

登录后才能评论

评论列表(0条)

保存