C_learn/3_lesson/06_var_global_static/main.c

22 lines
325 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
// 定义一个静态全局变量
// 静态全局变量只能在其定义的.c文件中任意位置使用不能跨文件使用
static int num;
void myfun()
{
num++;
}
int main(int argc, char *argv[])
{
printf("num = %d\n", num);
myfun();
printf("num = %d\n", num);
return 0;
}