#include<stdio.h> int main() { //交换两个数的值 // 方法一 可读性最好 int a = 10; int b = 11; int temp ; temp = a; a = b; b = temp; printf("a = %d, b = %d ",a, b); //方法二 int c = 10; int d = 11; c = d - c; d = d - c; c = d + c; printf("c = %d, d = %d ",c, d); // 方法三 int e = 10; int f = 11; e = e ^ f; f = e ^ f; e = e ^ f; printf("e = %d, f = %d ",e, f); return 0; }
a = 11, b = 10 c = 11, d = 10 e = 11, f = 10