It is Undefined Behavior, which means anything may happen.
Why is it UB?
The answer is simply that there is no ordering constraint, not even indeterminate sequencing, between a write of k
and a read of k
which is not used to determine the new value of k
.
printf ( "\n%d %d %d", k == 35, k = 50, k > 40 );
// No ordering constraint between function arguments.
Aside: If the write happened in a function called in the argument list instead (not in the arguments to that function), it would be indeterminately sequenced and thus not UB.
Indeterminately sequenced means it is sequenced before or after without determining which. It is not quite as bad as UB (anything goes), but it should still not be relied on, as the order is unreliable.
int SetVar(int *p, int v) {return *p = v;}
printf ( "\n%d %d %d", k == 35, SetVar(&k, 50), k > 40 );
// No ordering constraint between function arguments, but
// the function call is indeterminately ordered