Possible Duplicate:
Is this undefined C behaviour?
#include<stdio.h>
int main()
{
int a=5;
printf("%d %d %d",a++,a++,++a);
return 0;
}
Output:
In gcc:
7 6 8
In TURBO C:
7 6 6
Possible Duplicate:
Is this undefined C behaviour?
#include<stdio.h>
int main()
{
int a=5;
printf("%d %d %d",a++,a++,++a);
return 0;
}
Output:
In gcc:
7 6 8
In TURBO C:
7 6 6
Because the order of evaluation of arguments to a function is unspecified and may vary from compiler to compiler. An compile may evaluate function arguments from:
left to right or
right to left or
in any other pattern.
This order is not specified by the C standard.
Reference:
C99 Standard 6.5
"The grouping of operators and operands is indicated by the syntax.72) Except as specified later (for the function-call (), &&, ||, ?:, and comma operators), the order of evaluation of subexpressions and the order in which side effects take place are both unspecified."
The order of evaluation of arguments is unspecified. Compilers are free to implement it in any way they choose. Code like this will be brittle and unreliable.