操作precedence - 前pression评价 [英] Operator Precedence - Expression Evaluation

查看:117
本文介绍了操作precedence - 前pression评价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关以下code片段我得到的输出 1 。我想知道它是怎么来的?

 无效的主要()
{
INT X = 10,Y = 20,Z = 5,I;
我= X< Y< Z;
的printf(%D,我);
}


解决方案

I = X< Y< Z; ,获取PTED为跨$ P $ I =(X< Y)LT; Z ,从而得到PTED为 I = 1< Z ,其中计算结果为1。

For the following code snippet I get the output as 1. I want to know how it came?

void main()
{
int x=10,y=20,z=5,i;
i=x<y<z;
printf("%d",i);
}

解决方案

i=x<y<z;, gets interpreted as i=(x<y)<z, which in turn gets interpreted as i=1<z, which evaluates to 1.

这篇关于操作precedence - 前pression评价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆