x=x+1 vs. x +=1

后端 未结 17 1219
独厮守ぢ
独厮守ぢ 2020-12-29 02:57

I\'m under the impression that these two commands result in the same end, namely incrementing X by 1 but that the latter is probably more efficient.

If this is not c

17条回答
  •  自闭症患者
    2020-12-29 03:24

    If x is a simple integer scalar variable, they should be the same.

    If x is a large expression, possibly with side effects, +=1 and ++ should be twice as fast.

    Many people concentrate on this kind of low-level optimization as if that's what optimization is all about. I assume you know it's a much bigger subject.

提交回复
热议问题