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/
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)