#include<iostream>
using namespace std;
void swap0(int *pa,int *pb) // 指针方法
{
int tmp;
tmp = *pa;
*pa = *pb;
*pb = tmp;
}
void swap1(int &pa,int &pb) // 引用方法
{
int tmp;
tmp = pa;
pa = pb;
pb = tmp;
}
int main()
{
int a,b;
cin>>a>>b;
cout<<"a = "<<a<<",b = "<<b<<endl;
swap0(&a,&b);
cout<<"a = "<<a<<",b = "<<b<<endl;
swap1(a,b);
cout<<"a = "<<a<<",b = "<<b<<endl;
std::swap(a,b); //直接调用模板函数
cout<<"a = "<<a<<",b = "<<b<<endl;
return 0;
}
using namespace std;
void swap0(int *pa,int *pb) // 指针方法
{
int tmp;
tmp = *pa;
*pa = *pb;
*pb = tmp;
}
void swap1(int &pa,int &pb) // 引用方法
{
int tmp;
tmp = pa;
pa = pb;
pb = tmp;
}
int main()
{
int a,b;
cin>>a>>b;
cout<<"a = "<<a<<",b = "<<b<<endl;
swap0(&a,&b);
cout<<"a = "<<a<<",b = "<<b<<endl;
swap1(a,b);
cout<<"a = "<<a<<",b = "<<b<<endl;
std::swap(a,b); //直接调用模板函数
cout<<"a = "<<a<<",b = "<<b<<endl;
return 0;
}