Saturday, 17 August 2013

Undetermined behavior of post and pre increment operators in c [on hold]

Undetermined behavior of post and pre increment operators in c [on hold]

int a = 5;
int c = a++ + ++a + ++a;
This is what is done in a C code, i think c = 20 is correct but gcc-4.7.2
gives c = 19.

int a;
scanf("%d", &a);
int c = a++ + ++a + ++a;
This is what is done in a C code, i think c = 20 is correct but gcc-4.7.2
gives c = 18. (This is for a = 5 as input from user.)

Why is it so? please explain every basic concept involved.
Thanks!!!

No comments:

Post a Comment