a = (a + b) - (b = a); C++ vs php

前端 未结 3 605
臣服心动
臣服心动 2021-01-05 21:11

I\'ve been looking around and found formula: a = (a + b) - (b = a) it is supposed to swap two variables (or objects in some cases). However I tested it with C++

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-05 21:37

    C++ code is completely broken because of undefined behavior. (read and write b in one sequence point).

提交回复
热议问题