Why are global variables always initialized to '0', but not local variables? [duplicate]
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Why are global and static variables initialized to their default values? See the code, #include <stdio.h> int a; int main(void) { int i; printf("%d %d\n", a, i); } Output 0 8683508 Here 'a' is initialized with '0', but 'i' is initialized with a 'junk value'. Why? 回答1: Because that's the way it is, according to the C Standard . The reason for that is efficiency: static variables are initialized at compile-time ,