I am running my C code on gcc to understand pre/post increment operator. However the results that I see are not what I expected. Like for the line 6, since i is 5, it should have been
8 7 6 5 5
But it is 8 7 6 5 8
Then coming to the last line, it displays 14 14 14 14
. Can someone please explain this behavior. I had expected
14 14 13 12
Is this compiler dependent? Is the beahviour of printf function on sequence points undefined?
#include <stdio.h>
int main()
{
i = 5;
printf("%d %d %d %d %d \n", i, i++, i++, i++, i);
printf("%d \n", ++i);
printf("%d \n", ++i);
printf("%d \n", ++i);
printf("%d %d %d %d \n", i, ++i, ++i, ++i);
}