c - 后增量、前增量和运算符优先级

标签 c operators post-increment

答案是 45。我不明白这东西是如何工作的。

main()
{
    int a =10;
    int i =  a++ + ++a + a++ + ++a;
    printf("%d , %d ", i,a);

}

最佳答案

实际上输出是一个未定义的行为,这很好。

来自 C99 标准的是 6.5 表达式,§2

Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.

The order of evaluation of the operands is unspecified. If an attempt is made to modify the result of an assignment operator or to access it after the next sequence point, the behavior is undefined.

关于c - 后增量、前增量和运算符优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18515351/

相关文章:

c++ - 如何判断两个源文件是否生成功能相同的代码?

c - 这个 printf() 函数如何输出这些值?

c++ - 链式ostream内部行为及其在MSVC上的结果(与Clang相比)

c - putchar() 和 recur() 相关问题

java - 为什么后自增运算符不适用于返回 int 的方法?

c - 从 i386 移动到 x86_64 时的浮点精度

C 错误处理编码风格

java - 为什么 GetMethodID() 对不存在的方法不返回 NULL?

c - 当按位与应用于负数时会发生什么?

prolog - 斜线(/)在序言中做什么?