在C语言中,int x=3, y=4; 执行表达式: z=x>y?2:1.5, z的值为_____

在C语言中,int x=3, y=4; 执行表达式: z=x>y?2:1.5, z的值为_________。怎么理解

z是什么类型的变量

z=x>y?2:1.5,


这句的意思是x如果大于y那么z=2,否则z=1.5

不过还得看z是什么类型的变量如果z是float或者double

那么z的值为1.5

如果z是int 类型那么z的值是1

验证:

#include"stdio.h"
int main()
{
int x=3,y=4;
int z=x>y?2:1.5;
float z1=x>y?2:1.5;
printf("z=%d\n",z);
printf("z=%f",z1);
return 0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-06-28
1.5三则运算式
相似回答