I would like to know the explanation for the following expression evaluation in C under windows TURBO c..
void main()
{
int i=4;
int x;
x= ++i + ++i + ++i; // i becomes 5 then 6 added becomes 11 and then incremented to 12 so 11+12=23
printf("%d",x);
getch();
}
when the above was executed value of x comes out to be 21
Slightly eliminating the x variable in the above
void main()
{
int i=4;
printf("%d", ++i + ++i + ++i); //accordingly at this step 5+6+7=18
getch();
}
when the above is executed the answer comes out to be 18
Can anyone provide a decent explanation step by step and why two answers are different???
Thanks in advance.
Akshay