Your code produces undefined behavior. Function argument evaluations are not sequenced relative to each other. Which means that modifying access to x
in x=1
is not sequenced with relation to other accesses, like the one in x*1
. The behavior is undefined.
Once again, it is undefined not because you "used assignment operator or modifying value inside printf()", but because you made a modifying access to variable that was not sequenced with relation to other accesses to the same variable. This code
(x = 1) + x * 1
also has undefined behavior for the very same reason, even though there's no printf
in it. Meanwhile, this code
int x, y;
printf("%d %d", x = 1, y = 5);
is perfectly fine, even though it "uses assignment operator or modifying value inside printf()".
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…