I haven’t really understood the difference between

i++ and ++i

  • freely@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    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.