c - Is `y = x = x + 1;` undefined behavior? -
as title says, is
y = x = x + 1; undefined behavior in c?
answer question
no.
what happen
happen:
int x = 1; /* assume */ y = x = x + 1; /* results: */ y == 2; x == 2; how compiles
same as:
x += 1; y = x; why not undefined
because not writing x in same expression read it. set + 1, assign y value of x.
your future
if find code confusing can use parentheses readability:
y = x = (x + 1);
Comments
Post a Comment