Getting error in simplest concept of c

int main()
int a = 5;
int b = ++a * a++;
printf("%d ",b);
return 0;
my codeblocks ide is giving output 36
while on codechef’s ide output is 42.
pretty confused ryt now.

This is basically due to the concept of Sequence point. These are the points where all side-effects of previous evaluation have settled and there are no side-effects of the future subsequent evaluation. Between two sequence points (=,:wink: the value of the variable is getting modified more than once which is not allowed. Hence, the order of evaluation is undefined here and may vary compiler to compiler.
Refer this and this for more details.


Thank you @damn_me,earlier it made me feel like hitting rock bottom.

Haha… Happy to help, also mark it as accepted and close the thread, if satisfied. It helps other know the answers better and removes duplicacy as others may search for the same. I went across a very similar post today itself and I just referred that person to this… :slight_smile:

1 Like