Is x += 1 more efficient than x = x + 1?

前端 未结 6 1723
青春惊慌失措
青春惊慌失措 2020-12-03 22:08

In x = x + 1, is x evaluated twice? If so, does that mean in x += 1, x is only evaluated once? How are the two expression

6条回答
  •  情书的邮戳
    2020-12-03 22:49

    With gcc, you can get the assembler code with gcc -S foo.c. I tried it with x += 1 and x = x + 1 and it was the same.

提交回复
热议问题