Date: 2004-09-21 12:13 am (UTC)
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. :)
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

December 2015

S M T W T F S
  12345
6789101112
13141516171819
20212223242526
27 28293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 14th, 2025 03:20 pm
Powered by Dreamwidth Studios