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

前端 未结 17 2039
臣服心动
臣服心动 2020-11-21 17:15

We have the question is there a performance difference between i++ and ++i in C?

What\'s the answer for C++?

17条回答
  •  悲&欢浪女
    2020-11-21 18:14

    Mark: Just wanted to point out that operator++'s are good candidates to be inlined, and if the compiler elects to do so, the redundant copy will be eliminated in most cases. (e.g. POD types, which iterators usually are.)

    That said, it's still better style to use ++iter in most cases. :-)

提交回复
热议问题