我无法向自己解释为什么这会给出87.我的IDE是代码块和我的编译器GNU GCC编译器。
unsigned long getHigherValue(unsigned long Value1, unsigned long Value2);
int main(){
int a, b = 20;
b = 22;
/*============
It works fine if I replace the two lines above with "int a = 20; int b = 22"
=============*/
int c = getHigherValue(a, b);
printf("%d", c);
return 0;
}
unsigned long getHigherValue(unsigned long Value1, unsigned long Value2){
unsigned long HigherValue = Value2;
if(Value1 > Value2){
HigherValue = Value1;
}
if(Value1 == Value2){
HigherValue = 0;
}
return HigherValue;
}
输出:
87
答案 0 :(得分:10)
int a, b = 20;
这会使a
未初始化,b
初始化为20. a
的值不确定,因此您可以从您的程序中获得任何结果(即它是未定义的行为)。