C_learn/3_lesson/05_var_global/main.c

24 lines
460 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>
// 定义一个普通全局变量
// 只要是在main函数外也在子函数外的变量就是全局变量
// 如果全局变量没有进行初始化则系统自动将其初始化为0
int num;
// 全局变量可以在程序的任意一个位置进行对其的操作
void myfun()
{
num = 666;
}
int main(int argc, char *argv[])
{
printf("num = %d\n",num);
myfun();
printf("num = %d\n",num);
return 0;
}