in reply to Prefix and postfix increment/decrement operator query
Officially, the behaviour is undefined. The following documents what actually happens. It boils down to the fact that pre-increments and pre-decrements leave the input variable on the stack while post-increments and post-decrements leave a copy of it.
$a++ + ++$a $a Stack 1. Push copy of $a on stack 10 10 2. Increment $a 11 10 3. Increment $a 12 10 4. Push $a on stack 12 10,$a 5. Add 12 22
++$a + $a++ $a Stack 1. Increment $a 11 2. Push $a on stack 11 $a 3. Push copy of $a on stack 11 $a,11 4. Increment $a 12 $a,11 5. Add 12 23
Note: These steps don't correspond one-for-one to the ops actually involved for the sake of simplicity.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Prefix and postfix increment/decrement operator query
by saurabh.hirani (Beadle) on Jul 03, 2009 at 06:06 UTC |