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
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
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.