#include <stdio.h>
int g;
void afunc(int x)
{
g = x; /* this sets the global to whatever x is */
}
int main(void)
{
g = 10; /* global g is now 10 */
afunc(20); /* but this function will set it to 20 */
printf("%d\n", g); /* so this will print "20" */
return 0;
}
printf 的输出是 20。但是局部变量 g = 10,那么为什么它打印 20 而不是 10,局部变量的范围比全局变量大吗?