假定int a=2,b=3;,表达式(b/a*2.0>2.0*a/b)+(++a-b--)的值是?
为什么答案是0而不是1呢?
未定义行为,不要理了。
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 的求值顺序是不确定的。
a
b
2.1m questions
2.1m answers
60 comments
56.1k users