<分区>
Possible Duplicate:
Is there a performance difference between i++ and ++i in C++?
他们说 ++i
更快,但我不明白为什么。谁能告诉我这些运算符的汇编代码?
<分区>
Possible Duplicate:
Is there a performance difference between i++ and ++i in C++?
他们说 ++i
更快,但我不明白为什么。谁能告诉我这些运算符的汇编代码?
最佳答案
++i
绝对和 i++
一样快,但它可能更快。
原因在于实现。
为了实现 i++
,实现需要生成 i
的临时拷贝,这与 ++i
的实现不同。
但是智能编译器可以优化这个临时文件的生成,他们肯定会为 POD 类型做。
关于c++ - 运算符 x++;和++x;对于 int。哪个更快?为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8075809/