可能重复:
Is there a performance difference between i++ and ++i in C++?运算符x ++;和++ x;对于int.哪个更快?为什么?
他们说,++i
是快,但我不明白why.Can任何人告诉我这些运营商的汇编代码?
可能重复:
Is there a performance difference between i++ and ++i in C++?运算符x ++;和++ x;对于int.哪个更快?为什么?
他们说,++i
是快,但我不明白why.Can任何人告诉我这些运营商的汇编代码?
++i
确实如i++
一样快,但它可能会更快。
原因是执行。
为了实现i++
,实现需要生成i
的临时副本,与++i
的实现不同。
但智能编译器可以优化这种临时性的生成性,它们当然适用于POD类型。
这取决于编译器和情况,如果它为此表达式生成更快的代码。
请参阅这里:http://stackoverflow.com/questions/3346450/c-what-is-the-difference-between-i-and-i/3346729#3346729 – Azodious
@Abodious:C#!= C++ – Piskvor
这有之前被问过很多次了,除了提及引用外,还有http://stackoverflow.com/questions/2020184/preincrement-faster-than-postincrement-in-c-true-if-yes-why-is-it和http ://stackoverflow.com/questions/5223950/stl-iterators-prefix-increment-faster。 – hlovdal