比较三个数大小输出中间数~~纠错
比较三个数大小输出中间数。 #include<stdio.h>
int main(void)
{
int a,b,c;
int max,min;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
a > b
? max = a, min = b
: max = b, min = a;
min < c && c < max
? printf("%d\n",c)
: ( c < min ? printf("%d",min) : printf("%d",max));
return 0;
}
为什么gcc说 这一行 : max = b, min = a; 左值无效?
而在xp下用dev-cpp调试没有任何错误。高人给说说~~谢了先。
----------------解决方案--------------------------------------------------------
条件运算符优先级比赋值运算符和逗号运算符高;改成这样试试
a > b
? (max = a, min = b)
: (max = b, min = a);
----------------解决方案--------------------------------------------------------
那这种初级错误dev-cpp也能检查出来啊~~问题是它不尽编译通过,测试结果也正确。
----------------解决方案--------------------------------------------------------
没人给个更好的解释么?
----------------解决方案--------------------------------------------------------
没有什么好解释的,自己加括号就得了
[color=white]
----------------解决方案--------------------------------------------------------
我需要解释的是:
dev-cpp调试没有任何错误执行结果也正确
----------------解决方案--------------------------------------------------------
编译器挂了?
----------------解决方案--------------------------------------------------------
编译器智能程度高,不能代表些什么吧
请问你用的哪个gcc??
[color=white]
----------------解决方案--------------------------------------------------------
运算符优先级不一样!
----------------解决方案--------------------------------------------------------
----------------解决方案--------------------------------------------------------