I haven’t really understood the difference between

i++ and ++i

You are viewing a single thread.
View all comments View context
1 point

Yeah the value copy is necessary to return the old (pre-increment) value with i++. However, your compiler is (usually) smart enough to optimize the copy away if you never use it.

That being said, being explicit is good, so use ++i if you don’t need the old value. Don’t depend on the compiler to maybe do something.

permalink
report
parent
reply

C & C++

!cpp@lemmy.ml

Create post

Community stats

  • 19

    Monthly active users

  • 73

    Posts

  • 41

    Comments

Community moderators