/*#include <iostream>
using namespace std;
main()
{
---------------------(一)----------------------------------
int i = 90 ;
int* p = NULL;
cout << "P = " << p << endl; //00000000
//cout << "*P = " << *p << endl;
p = &i;
cout << "P = " << p << endl; //0012ff44
cout << "P = " << p << endl; //90
i = 80; //i改变值,但地址不变。。因此p指向地址不变,但p(&p)改变了。
cout << "P = " << p << endl; //0012ff44
cout << "*P = " << *p << endl; //80
*p = 150; //将指向地址的值改变,也改变i的值。
cout << " P = " << p << endl; //0012ff44
cout << "P = " << p << endl; //150
cout << " i = " << i << endl; //150
/
/int a = 100;
int b = 300;
swap(&a, &b);
//swap(a ,b);
int p = &a;
int q = &b;
cout << "*p = " << p <<endl; //100
cout << "q = " << q <<endl; //300
swap(p, q);
cout << "p = " << p <<endl; //300
cout << "q = " << *q <<endl; //100
cout << "a = " << a <<endl; //100
cout << "b = " << b <<endl; //300 //只改变地址指向,不改变函数地址
return 0;
}
void swap(int a,int b)
{
int t = a ;
a = b;
b = t;
}
void swap(int* a,int* b)
{
int* t = a ;
a = b;
b = t;
}*/
include <iostream>
using namespace std;
void swap(int &a, int &b)
{
//方法一:
//int tmp = 0;
// tmp = b;
// b = a;
// a = tmp;
//方法二:
//a = a+b;
//b = a-b;
//a = a -b;
//同理
// a = a - b; //-1 = 3-4
// b = a + b; // 3 = -1 + 4
// a = b - a; // 4 = 3 - -1;
//方法三:
//a ^= b ^= a ^= b; //a=a^b; b=b^a; a=a^b; 恩,理解了。异或运算得出的(a^b)。与a异或得出b,与b异或得出a
//方法四:
a = a+b-(b=a); // b= 3; a = 3+3-3;
}
int main(void)
{
int a = 3;
int b = 4;
int t =a^b;
cout << t <<endl;
b=b^t;
cout << b <<endl;
a=t^b;
cout << a <<endl;
cout << "a = " << a <<endl;
cout << "b = " << b <<endl; //300
swap(a , b);
cout << "a = " << a <<endl; //100
cout << "b = " << b <<endl; //300
cin >>a;
return 0;
}