88 66
88 66 66 88
把变量的引用作为函数形参,即传送变量的别名.
#include <iostream>
using namespace std;
//“引用形参”交换函数
void swap(int &a, int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}
//主函数
int main()
{
int x,y;
cin >> x >> y;
//交换前
cout << x << " " << y << endl;
//调用交换函数
swap(x,y);
//交换后
cout << x << " " << y << endl;
return 0;
}
原文地址:http://blog.csdn.net/u013634961/article/details/39022523