this post was submitted on 24 Aug 2021
3 points (100.0% liked)

C & C++

982 readers
1 users here now

founded 5 years ago
MODERATORS
 

I haven't really understood the difference between

i++ and ++i

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 3 years ago

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.