分析一下这个C语言小程序的运行结果

#include "stdio.h"
void main()
{
int a=5,b=4,c=3,d=2;
if(a>b>c)
printf("%d\n",d);
else if((c-1>=d)==1)
printf("%d\n",d+1);
else
printf("%d\n",d+2);
}

输出 3
程序执行到
if(a>b>c) 时先判断a>b,结果为true,又因为c语言里true用1表示
所以if(a>b>c)就变成了if(1>c) 结果是false ,所以执行else if((c-1>=d)==1)
同样,当c-1>=d为true 所以c-1>=d就为1,1==1也为true
所以最后执行 printf("%d\n",d+1);
所以最后的结果为3
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-11-17
printf("%d\n",d+1);
结果打印的是3
if(a>b>c):a>b成立,得到结果为1,1>c,不成立,所以整个表达式的结果为0;
else if((c-1>=d)==1):c-1==d,所以(c-1>=d)表达式的值为1,1==1,
第2个回答  2011-11-17
输出 printf("%d\n",d+1);
第3个回答  2011-11-17
结束是 3
相似回答
大家正在搜