#include <iostream>
using std::cout;
using std::endl;
void swap1(int a,int b){
cout << "--------------" << endl;
cout << "a的地址=" << &a << endl;
cout << "a的值为=" << a << endl;
cout << "b的地址=" << &b << endl;
cout << "b的值为=" << b << endl;
int temp = a;
a = b;
b = temp;
cout << "--------------" << endl;
cout << "a的地址=" << &a << endl;
cout << "a的值为=" << a << endl;
cout << "b的地址=" << &b << endl;
cout << "b的值为=" << b << endl;
}
void swap2(int* a,int* b){
cout << "--------------" << endl;
cout << "a的地址=" << &a << endl;
cout << "a的值为=" << a << endl;
cout << "b的地址=" << &b << endl;
cout << "b的值为=" << b << endl;
int temp = *a;
*a = *b;
*b = temp;
cout << "--------------" << endl;
cout << "a的地址=" << &a << endl;
cout << "a的值为=" << a << endl;
cout << "b的地址=" << &b << endl;
cout << "b的值为=" << b << endl;
}
void swap3(int& a,int& b){
cout << "--------------" << endl;
cout << "a的地址=" << &a << endl;
cout << "a的值为=" << a << endl;
cout << "b的地址=" << &b << endl;
cout << "b的值为=" << b << endl;
int temp = a;
a = b;
b = temp;
cout << "--------------" << endl;
cout << "a的地址=" << &a << endl;
cout << "a的值为=" << a << endl;
cout << "b的地址=" << &b << endl;
cout << "b的值为=" << b << endl;
}
int main(){
int a = 2;
int b = 3;
cout << "a的地址=" << &a << endl;
cout << "a的值为=" << a << endl;
cout << "b的地址=" << &b << endl;
cout << "b的值为=" << b << endl;
//swap1(a,b);
//swap2(&a,&b);
swap3(a,b);
cout << "--------------" << endl;
cout << "a的地址=" << &a << endl;
cout << "a的值为=" << a << endl;
cout << "b的地址=" << &b << endl;
cout << "b的值为=" << b << endl;
system("pause");
}