标签:span int bsp col style 安全 ++ 交换 越界
1. C++
int a = 0,b = 1;
(1)借助中间变量:
int tmp = a; a = b; b = tmp;
(2)相加或相乘的方法
有越界的危险
a = a + b; b = a - b; a = a - b;
a = a*b; b = a/b; a = a/b;
(3)异或
快且安全
a = a ^ b; b = a ^ b; a = a ^ b;
标签:span int bsp col style 安全 ++ 交换 越界
原文地址:https://www.cnblogs.com/taoXiang/p/12343627.html