#include
using name space std;
void swap1(int a,int b)
{
int t;
t=a;
a=b;
b=t;
}
void swap2(inta,intb)
{
int t;
t=*a;
*a=*b;
*b=t;
}
int main()
{
int a=2,b=5,*p=&a,*p=&b;
swap2(p,q);
cout<<*p<<","<<*q<<endl;
swap1(a,b);
cout<<*p<<","<<*q<<endl;
return 0;
}
swap1实现不了数据交换
swap2可以实现数据交换
所以两个cout输出都是5,2