异或法
只支持整型变量
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main() {
int a = 3,b = 4;
a = a ^ b;// 0011 ^ 0100 = 0111
b = a ^ b;// 0111 ^ 0100 = 0011
a = a ^ b;// 0111 ^ 0011 = 0100
printf("a = %d,b = %d\r\n", a, b);
return 0;
}
加减法
支持整型和浮点型(会出现精度丢失)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main() {
int a = 3,b = 4;
a = a + b;// 3 + 4 = 7
b = a - b;// 7 - 4 = 3
a = a - b;// 7 - 3 = 4
printf("a = %d,b = %d\r\n", a, b);
return 0;
}
乘除法
支持整型和浮点型(会出现精度丢失,b != 0)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main() {
int a = 3,b = 4;
a = a * b;// 3 * 4 = 12
b = a / b;// 12 / 4 = 3
a = a / b;// 12 / 3 = 4
printf("a = %d,b = %d\r\n", a, b);
return 0;
}