以下代码生成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