Redefined Global variable
问题 I'm a little Confused about this code result: #include <stdio.h> int g; void afunc(int x) { g = x; /* this sets the global to whatever x is */ } int main(void) { int g = 10; /* Local 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; } Why the result is 10 Not 20 ? 回答1: Calling afunc changes the global g , and main retains its local g . Entering a function doesn’t swap its scope with the global scope. Each function*