The behavior of this is undefined.
http://c-faq.com/expr/ieqiplusplus.html
>Both your example are the same.
No, they are as described.
Think about this:
Code:
while ( a++ < 10 )
printf("%d\n", a);
Compare the current value of
a with 10, then increment
a and enter the loop.
And this:
Code:
while ( ++a < 10 )
printf("%d\n", a);
Increment the value of
a, then compare it with 10 and enter the loop.
In either case,
a is incremented before it enters the loop. If
a is 0 before the loop, then in either case it will be 1 on the first iteration.
Now,
Code:
a=0;
while(a<10) {
a++
}
Do nothing to
a, compare to 10, the enter the loop (which increments
a).
All three are different. All three produce different results.