c 中赋值的混淆

Shy*_*nna 1 c postfix-mta variable-assignment conditional-operator postfix-operator

#include<stdio.h>
int main()
{
 int a=0, b=1, c=3;
 *((a) ?&b :&a) = a ? b : c; 
 printf("%d %d %d\n", a, b, c);
 return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:3 1 3

赋值运算符的结合性是从右到左。所以这里我们得到了 3 1 3 但是......

#include<stdio.h>
int main()
{
 int a=0, b=1, c=3;
 *((a++) ?&b :&a) = a ? b : c;
 printf("%d %d %d\n", a, b, c);
 return 0;
}

Run Code Online (Sandbox Code Playgroud)

输出:1 1 3

My doubt is why 1 1 3 is returned instead of 1 3 3 ?
Run Code Online (Sandbox Code Playgroud)

dbu*_*ush 6

你在这里看到的是未定义行为的表现。

操作顺序仅决定操作数的分组方式。它并没有规定在其子表达式的计算顺序。

在这个表达式中:

*((a++) ?&b :&a) = a ? b : c;
Run Code Online (Sandbox Code Playgroud)

唯一的保证是a++将在&bor之前进行评估&a,并且a将在bor之前进行评估c。有没有评价之间的测序a++a,让你有一个读和可变的无序列点写。