同样对于交换两个数的值
1.引用传递:函数原型声明:void swap(int &a,int &b)
函数定义:swap(int &a,int &b){
int temp;
temp=a;
a=b;
b=temp;
}
函数调用:swap(a,b);
2.值传递:函数原型声明:void swap(int a,int b)
函数定义:swap(int a,int b){
int temp;
temp=a;
a=b;
b=temp;
}
函数调用:swap(a,b);
3.地址传递:函数原型声明:void swap(int *p,int *q)
函数定义:swap(int *p,int *q){
int temp;
temp=*p;
*p=*q;
*q=temp;
}
函数调用:swap(&a,&b);