本文介紹了++i 或 i++ 在 for 循環(huán)中 ??的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
可能的重復(fù):
i++和++有性能差異嗎我在 C++ 中?
為什么有些程序員在普通的 for 循環(huán)中編寫 ++i
而不是編寫 i++
?
Is there a reason some programmers write ++i
in a normal for loop instead of writing i++
?
推薦答案
對于整數(shù),前后自增沒有區(qū)別.
For integers, there is no difference between pre- and post-increment.
如果 i
是一個非平凡類的對象,那么通常首選 ++i
,因為該對象被修改然后被評估,而 i++
在求值后修改,所以需要復(fù)制一份.
If i
is an object of a non-trivial class, then ++i
is generally preferred, because the object is modified and then evaluated, whereas i++
modifies after evaluation, so requires a copy to be made.
這篇關(guān)于++i 或 i++ 在 for 循環(huán)中 ??的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!