void swap(int* ip1, int* ip2){
int temp;
temp = *ip1;
*ip1 = *ip2;
*ip2 = temp;
}
int main()
{
int a=5, b=7;
swap(&a,&b);
cout<<"a="<<a<<" "<<"b="<<b<<endl;
return 0;
}
传引用类型的
void swap(int &ival1, int &ival2){
int temp;
temp = ival1;
ival1 = ival2;
ival2 = temp;
}
int main()
{
int a=5, b=7;
swap(a,b);
cout<<"a="<<a<<" "<<"b="<<b<<endl;
return 0;
}