Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)
Undefined Behavior and Sequence Points
Ok we all know that i++ increments value by 1 on next line and ++i increments on same line
(please correct me if i am wrong there )
so for a sample statement of c as follows:
int a=0;
printf("%d , %d",++a,a);
the expected output should be 1 , 1
but instead it gives 1 , 0
so as one might guess what i am asking here is why does the second linking of
i
print 0
instead of 1
when the value is already incremented.
So if post increment didn't increment value in the same line then what is the
difference between post and pre increment?
edit : changed the name of variable from i to a to avoid grammatical confusion.