在這段代碼中,爲什麼在我的測試中結果始終是1
,2
和3
?爲什麼未初始化的局部變量總是具有相同的初始值?
#include <stdio.h>
void test() {
int a;
a++;
printf("%d",a);
}
int main(int argc, char *argv[]) {
test();
test();
test();
}
我認爲test()
中的變量是靜態的,不是嗎?爲什麼?
http://stackoverflow.com/questions/1597405/what-happens-to-a-declared-uninitialized-variable-in-c-does-it-have-a-value – adt