引用(交换数值)

来源:互联网 发布:春英广场舞网络一线牵 编辑:程序博客网 时间:2024/05/21 14:53
1 #include<iostream>  2 using namespace std;  3   4 void fun(int &a,int &b);//声明一个函数  5 int main()  6 {  7     int x=10;  8     int y=20;  9     cout<<x<<","<<y<<endl; 10     fun(x,y); 11     cout<<x<<","<<y<<endl; 12     return 0; 13 } 14 void fun(int &a,int &b) 15 { 16     int c=0; 17     c=a; 18     a=b; 19     b=c; 20  21  22 }