Search code examples
c++for-looppost-incrementpre-increment

++i or i++ in for loops ??


Possible Duplicate:
Is there a performance difference between i++ and ++i in C++?

Is there a reason some programmers write ++i in a normal for loop instead of writing i++?


Solution

  • For integers, there is no difference between pre- and post-increment.

    If i is an object of a non-trivial class, then ++i is generally preferred, because the object is modified and then evaluated, whereas i++ modifies after evaluation, so requires a copy to be made.