I have a small code in C
#include<stdio.h>
int main()
{
int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);
return 0;
}
Turbo C gives the following Output (as expected)
22,13,13,13
But GCC (used ubuntu and Code blocks compiler in windows) gives the following
22,13,14,14
I believe that Turbo c output was correct, but how come GCC is returning different output?
This is an undefined behaviour. As in C there is no specification of function argument evaluation, so the compiler is free to do it in any way. It is undefined and arbitrary.
C99 standard 6.5.:-