C语言试题疑问

发布于 2022-09-12 04:02:31 字数 79 浏览 23 评论 0

假定int a=2,b=3;,表达式(b/a*2.0>2.0*a/b)+(++a-b--)的值是?

为什么答案是0而不是1呢?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风筝有风,海豚有海 2022-09-19 04:02:31

未定义行为,不要理了。

Expressions/2

2 If a side effect on a scalar object is unsequenced relative to either a different side effect on the same scalar object or a value computation using the value of the same scalar object, the behavior is undefined. If there are multiple allowable orderings of the subexpressions of an expression, the behavior is undefined if such an unsequenced side effect occurs in any of the orderings.

后一个括号里对 a b 的修改与前一个括号里对 a b 的求值顺序是不确定的。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文