gpt4 book ai didi

c++ - l+l++ 和 l+l 一样吗?

转载 作者:太空宇宙 更新时间:2023-11-04 14:46:26 25 4
gpt4 key购买 nike

话说,尾部的++在这里没有实际作用?

最佳答案

l+l++ 未定义。您的表达式中没有序列点来分隔对 l 的访问和后增量。它可以做任何事情,包括具有与 l+l 相同的效果。

编辑:问题和答案在 Why is `i = ++i + 1` unspecified behavior?解释什么是序列点,引用标准的相关部分并提供链接。让我再次引用:

Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified. 53) Between the previous and next sequence point a scalar object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored.

强调我的。

第二次编辑:应大众要求,段落中的下一句:

The requirements of this paragraph shall be met for each allowable ordering of the subexpressions of a full expression; otherwise the behavior is undefined.

关于c++ - l+l++ 和 l+l 一样吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2842866/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com