救急 明天就要考试了

来源:百度知道 编辑:UC知道 时间:2024/05/30 21:31:10
#include "stdio.h"
main()
{int a=2,b= -1,c=2,y;
y=b++;
if(a<b) if(b<0) c=0;
else c++;
printf("%d,%d",c,y); }

这个C为什么输出=2
生是看不懂。。
不是定义了C=0吗?

if(a<b) if(b<0) c=0;
else c++;
上面的就是:if(a<b) {if(b<0) c=0; else c++; }由于a<b不成立,所以不执行大括号内的语句!!!要知道else总是和他最近的if相配,所以,相当于加大括号!!!

#include "stdio.h"
main()
{int a=2,b= -1,c=2,y;
y=b++; /* y=b,b++*/
if(a<b)
if(b<0)
c=0;
else
c++;
printf("%d,%d",c,y);
}
当a<b时:若b<0,则c=0;
若b>=0,c=c+1.
本题中,a=2,b=-1.
所以不执行。
故c=2,y=b=-1.