Preincrement比postincrement在C ++ - 真的吗?如果是,为什么呢? [英] Preincrement faster than postincrement in C++ - true? If yes, why is it?
本文介绍了Preincrement比postincrement在C ++ - 真的吗?如果是,为什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我听说这个preincrements(++ i)比C ++中的postincrements(i ++)有点快。真的吗?这是什么原因呢?
I heard about that preincrements (++i) are a bit faster than postincrements (i++) in C++. Is that true? And what is the reason for this?
推荐答案
后增量通常涉及保持上一个值的副本,额外代码。预增量只是做它的工作,并得到的方式。我通常预先增加,除非语义将改变,后增量实际上是必要的。
Post-increment usually involves keeping a copy of the previous value around and adds a little extra code. Pre-increment simply does it's job and gets out of the way. I typically pre-increment unless the semantics would change and post-increment is actually necessary.
这篇关于Preincrement比postincrement在C ++ - 真的吗?如果是,为什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文