1 #include <iostream>
2
3 using namespace std;
4
5 void test(int &a,int &b){
6 //c++中引入了引用,则可直接使用引用来改变main中变量a和b的值,其实引用的实现还是用的const *的形式去实现的
7 int temp;
8 temp=a;
9 a=b;
10 b=temp;
11 cout<<a<<" in c++ "<<b<<endl;
12 }
13
14 void test(int *a,int *b){
15 //在c中我们只能用改变指针的数值来改变在main中变量a和b的值
16 int temp;
17 temp=*a;
18 *a=*b;
19 *b=temp;
20 cout<<*a<<" in c "<<*b<<endl;
21 }
22
23 int main()
24 {
25 int a=10;
26 int b=20;
27 //test(&a,&b);
28 test(a,b);
29 cout<<a<<" "<<b<<endl;
30 return 0;
31 }