a = 5;
c = (b =a+2) - (a=1);
In book c programming a modern approach by kn king it is written that the effect of executing the second statement will result in 6 or 2 as it is undefined behavior of c but in other books like c by Dennis it is written that it will be executed from left to right. Which one is correct?
In the above case,
the value of
a
is being changed and being read without a sequence point in between, so it is undefined behavior.Quoting
C11
, Annex §J.2, Undefined behaviorAlso related, from chapter §6.5
So, there's no guarantee which subexpression will get evaluated first.