下面来看一段程序:
#include
int a1, a2;
float b1, b2;
char c1, c2;
int main(void)
{
int a3, a4;...float b3, b4;
char c3, c4;
printf("全局变量:a1 = %d, a2 = %d, b1 = %f, b2 = %f, c1 =%d, c2 =%d\n", a1,...a2, b1, b2, c1, c2);
printf("局部变量:a3 = %d, a4 = %d, b3 = %f, b4 = %f, c3 =%d, c4 =%d\n", a3, a4, b3..., b4, c3, c4);
return 0;
}
程序运行结果为:
全局变量:a1 = 0, a2 = 0, b1 = 0.000000, b2 = 0.000000, c1 =0, c2 =0...局部变量:a3 = 4200660, a4 = 4200754, b3 = 0.000000, b4 = 0.000000, c3 =0, c4 =0
可见,全局变量的默认初值为0。