1 #include <iostream> 2 #include <string> 3 4 using namespace std; 5 6 void ptrswap(int *&v1, int *&v2)//交换指针所指的地址 7 { 8 cout << endl; 9 cout << *v1 << " " << *v2 << endl; 10 int *tmp = v1; 11 v1 = v2; 12 v2 = tmp; 13 cout << *v1 << " " << *v2 << endl; 14 cout << endl; 15 } 16 17 int main() 18 { 19 int i = 10; 20 int j = 20; 21 int *pi = &i; 22 int *pj = &j; 23 cout << *pi << " " << *pj << endl; 24 ptrswap(pi, pj); 25 cout << *pi << " " << *pj << endl; 26 return 0; 27 }