#include <stdio.h> void exchange0(int *a ,int *b) //通过指针交换两者的值 { int c; c = *a; *a = *b; *b= c; } void exchange1(int *a,int *b) //没有交换两者的值,只是交换了地址 { int *c; c = a; a=b; b=c; } void exchange2(int &a,int&b)//通过引用交换两者的值 { int c; c = a; a= b; b=c; } void exchange3(int &a,int &b)//通过异或交换两者的值 { a =a^b; b= a^b; a = b^a; } void main() { int a=3,b=4; exchange0(&a,&b); printf("%d\t%d\n",a ,b); exchange1(&a,&b); printf("%d\t%d\n",a ,b); exchange2(a,b); printf("%d\t%d\n",a ,b); exchange3(a,b); printf("%d\t%d\n",a ,b); }