#include <stdio.h>
int main(void)
{
int i = 0;
i = i++ + ++i;
printf("%d\n", i); // 3
i = 1;
i = (i++);
printf("%d\n", i); // 2 Should be 1, no ?
volatile int u = 0;
u = u++ + ++u;
printf("%d\n", u); // 1
u = 1;
u = (u++);
printf("%d\n", u); // 2 Should also be one, no ?
register int v = 0;
v = v++ + ++v;
printf("%d\n", v); // 3 (Should be the …Run Code Online (Sandbox Code Playgroud) c increment operator-precedence undefined-behavior sequence-points
在C++中,以下是否有未定义的行为:
int i = 0;
(i+=10)+=10;
Run Code Online (Sandbox Code Playgroud)
在我对C和C++中+ =的结果的答案的评论中有一些争论?这里的微妙之处在于默认响应似乎是"是",而正确的答案似乎是"它取决于C++标准的版本".
如果它确实取决于标准的版本,请解释UB的位置和不在的位置.