引用传递方式交换3个变量的值

来源:互联网 发布:网易企业邮箱 mac 编辑:程序博客网 时间:2024/06/14 22:55

 #include <iostream.h>
void swap(int&,int&,int&);
void main()
{
 int a=99, b=5,c=39;
 cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl;
 swap(a,b,c);
 cout<<"swapped:"<<endl;
 cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl;
}
 void swap(int&x,int&y,int&m)
 {
  int temp;
  temp=x;
  x=y;
  y=m;
  m=temp;
 }

原创粉丝点击