Conceptually, if you're saying nothing but "increment i", then they're the same.
However, under the hood, there's one big difference when you're worried about memory, especially when using the ++/-- operators with bigger types than ints:
Since the postfix version returns the value of i, *then* increments, it actually returns a copy of i, then increments i, so that the expression will still get the old value of i. When you use the prefix, the new value is being returned, so everything just happens *to i* in place.
Not a huge deal unless you're worried about memory, or you implement ++ or -- for a particlaryly large class/struct, and aren't thinking about behind-the-scenes copying.
Other than that, it's all really which value of i you want. :)
no subject
Date: 2004-09-21 12:13 am (UTC)However, under the hood, there's one big difference when you're worried about memory, especially when using the ++/-- operators with bigger types than ints:
Since the postfix version returns the value of i, *then* increments, it actually returns a copy of i, then increments i, so that the expression will still get the old value of i. When you use the prefix, the new value is being returned, so everything just happens *to i* in place.
Not a huge deal unless you're worried about memory, or you implement ++ or -- for a particlaryly large class/struct, and aren't thinking about behind-the-scenes copying.
Other than that, it's all really which value of i you want. :)