c++关于引用、指针、值交换问题

 1 #include <iostream>
 2 void swapr(int& a,int& b);
 3 void swapp(int* p,int* q);
 4 void swapv(int a,int b);
 5 
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int value1=100,value2=200;
11     cout<<"value1:"<<value1<<" value2:"<<value2<<endl;
12     cout<<"refence swap:"<<endl;
13     swapr(value1,value2);
14     cout<<"value1:"<<value1<<" value2:"<<value2<<endl;
15     cout<<"point swap:"<<endl;
16     swapp(&value1,&value2);
17     cout<<"value1:"<<value1<<" value2:"<<value2<<endl;
18     cout<<"value swap :"<<endl;
19     swapv(value1,value2);
20     cout<<"value1:"<<value1<<" value2:"<<value2<<endl;
21     return 0;
22 }
23 void swapr(int& a,int& b)
24 {
25     int temp;
26     temp=a;
27     a=b;
28     b=temp;
29 }
30 void swapp(int* p,int* q)
31 {
32     int temp;
33     temp=*p;
34     *p=*q;
35     *q=temp;
36 }
37 void swapv(int a,int b)
38 {
39     int temp;
40     temp=a;
41     a=b;
42     b=temp;
43 }
原文地址:https://www.cnblogs.com/luoweiKnowledge/p/4120642.html