以下代碼生成y是答案,但我從未將42賦值給y,y怎麼能是42?未賦值變量的值爲
#include <stdio.h>
void doit2(void)
{
int x;
int y;
if (x == 42)
{
printf("x is the answer\n");
}
else if (y == 42)
{
printf("y is the answer\n");
}
else
{
printf("there is no answer\n");
}
}
void doit1(int a)
{
int b = a;
}
int main(void)
{
doit1(42);
doit2();
}
你應該問「它怎麼可能不是42」? –
你期望y是什麼? – recursive
Duplicate:http://stackoverflow.com/questions/1225788/uninitialized-values-being-initialized/1225790 – GManNickG