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 << "\t\t" << *v2 << endl;
10     int *tmp = v1;
11     v1 = v2;
12     v2 = tmp;
13     cout << *v1 << "\t\t" << *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 << "\t\t" << *pj << endl;
24     ptrswap(pi, pj);
25     cout << *pi << "\t\t" << *pj << endl;
26     return 0;
27 }

 

posted on 2013-09-10 10:04  可笑痴狂  阅读(272)  评论(0编辑  收藏  举报