Is there a performance difference between i++ and ++i in C?

前端 未结 14 1001
遥遥无期
遥遥无期 2020-11-22 10:08

Is there a performance difference between i++ and ++i if the resulting value is not used?

14条回答
  •  不知归路
    2020-11-22 10:50

    In C, the compiler can generally optimize them to be the same if the result is unused.

    However, in C++ if using other types that provide their own ++ operators, the prefix version is likely to be faster than the postfix version. So, if you don't need the postfix semantics, it is better to use the prefix operator.

提交回复
热议问题