#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 不会局部变量具有比全局变量更多范围?全局变量和局部变量混淆
代码中的实际注释解释了它。 XD – Archimaredes