C如何评估比探索少?
我想知道如何用C语言对此代码进行评估?
int x = 10, y = 20, z = 5, i;
i = x < y < z;
printf("%d\n",i);
I would like to know how i is evaluated in this code in C language ?
int x = 10, y = 20, z = 5, i;
i = x < y < z;
printf("%d\n",i);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关系运算符的结果是整数1如果条件为真,则是0。关系运营商从左到右评估。
因此,此语句
等同于
x,因此x小于y,因此它也可以像1初始化变量i的初始化一样重写,
1小于5。
因为
如果您像这样重写语句
,那么表达式的结果将等于0,因为y不小于z。
The result of a relational operator is either integer 1 if the condition is true or 0 otherwise. And relational operators evaluates from left to right.
So this statement
is equivalent to
and as x is less than y then it can be also rewritten like
that initialize the variable i by 1 because 1 is less than 5.
From the C Standard (6.5.8 Relational operators)
If you will rewrite the statement like
then the result of the expression will be equal to 0 because y is not less than z.