i++ or ++i

Hi, mates!
I cant remember where i heard it, but i know that in loops, for example
1
2
 for(int i=0; i <=100; ++i)
  {...}

it is more efficien to use ++i than i++. Can anyone explain why is this so ?
The difference was just 1 ASM instruction. Post-Increment would do a copy then increment, pre-increment wouldn't do the copy.

Nowadays, it likely doesn't matter as the compiler would prob just generate the most efficient code.
Thank you! :)
Though it can be more overhead if "i" is not of a "simple" type such as int.

Always use pre-increment unless you truly need the value of "i" before it
is incremented.
Typically, post increment (i++) requires a temporary, whereas pre increment doesn't.
Topic archived. No new replies allowed.