Possible Duplicate:
Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…)
Please explain the reason for the following outputs.
#include <stdio.h>
int main()
{
int i = 0, j = 0;
int val1 = 0;
int val2 = 0;
val1 = i+++i+++i++ ;
val2 = ++j+++j+++j ;
printf("value = %d\n", val1);
printf("value = %d\n", val2);
return 0;
}
Output :
value = 0
value = 7
You are modifying the same variable more than once without an intervening sequence point, this is Undefined Behavior.
An Undefined behavior simply means that there may or may not be any feasible explanation to the behavior of the program.
Good Read:
Undefined behavior and sequence points