I want to do something like this printf("%d,%d",array[c], array[c+1])
, with only one variable that increases in every iteration. I wrote the following code, and I expected "1,2" to stdout, I was wrong:
#include <stdio.h>
int main()
{
int c = 1;
printf("%d,%d",c++,c++); /* 2,1 */
//printf("%d,%d",c,c++); /* 2,1 */
//printf("%d,%d",c++,c); /* 1,2 */
}
If I try doing printf("%d,%d",c++,c)
and printf("%d,%d",c,c++)
, I can see that there is no defined order of execution of the "c++" statements.
Could somebody explain how the code I wrote compiles to ? And why and how does it change according to the position of the "c++" statements.