Originally posted by Enamul Haque:
so,
i++;
is equavalant to i=i+1;
so
i = i++;
means
i = i = i+1;
isn't it
It's not equivalent. The pre/postfix operators (++ and --) are unary. All of the arithmetic operators (+, -, * etc.) are binary. Binary in the sence that it requires two operands. The statement i=i+1 as you probably already know is programmer shorthand for:
Grab the contents of i
Add 1
Return the sum
Store the sum at i
The term i+1 has absolutetly no effect on i. But the unary operators
do affect their operand. i++ means:
Grab the contents of i
Add 1
Store the sum at i
Return i (original value)
For ++i:
Grab the contents of i
Add 1
Store the sum at i
Return the sum
So the effect of i=i++ is to temporarily store i+1 at i but then when it returns the original value, that is stored at i so no final change takes place.
[ June 30, 2003: Message edited by: Michael Morris ]
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher