I always forget which of i++
and ++i
return which value. To test this I wrote the fallowing code:
int i;
i = 6;
printf ("i = %d, i++ = %d\n",i, i++);
printf ("i = %d, ++i = %d\n",i, ++i);
The resulting (unexpected and strange) output is:
i = 7, i++ = 6
i = 8, ++i = 8
But when I break down the printf
s to 4 separate commands, I get the expected result:
printf ("i = %d, ",i);
printf ("i++ = %d\n",i++);
printf ("i = %d, ",i);
printf ("++i = %d\n",++i);
gives:
i = 6, i++ = 6
i = 7, ++i = 8
Why does this happens?