Thursday, December 1, 2011

++i OR i++ ?

From discussions on stack overflow we have:
  1. ++i does not expect to return a value while i++ might need to return a value.
  2. A modern compiler, for simple data types (i.e. integer) will treat the two the same if the context is right e.g. in a for loop
  3. For an object (e.g. an interator), however, ++i will be faster than i++ because a compiler cannot optimize away the creation of a temporary object for i++

No comments:

Post a Comment