#include <stdio.h>
int main()
{
int i = -1, j = -1;
printf("%d %d %d \n", i++, ++i, ++i);
printf("%d %d %d \n", ++j, ++j, j++);
return 0;
}
output:
1 2 2
2 2 -1
to me it seems like the output should have been
-1 2 2
2 2 1
or something, but it is not the case. It seems like the compiler is executing the increments from right to left. return the rightmost j (-1) then increment it, increment leftmost and middle j's and then return (2), resulting in 2 2 -1. I thought compiler reads from left to right. Is there something I am missing? I dont think that this is undefined behaviour, because the output is consistent, I tried it many times and it yields the same result every time. The difference between this question and my question is that in my code, I dont make assignments to the original variable, and the incrementions are seperated with commas.