您的位置:首页 > 编程语言 > C语言/C++

第一周 项目1 C++语言中函数参数传递的三种方式

2015-09-07 16:58 351 查看
#include<iostream>
using namespace std;
<span style="color:#ff0000;">void myswap(int x, int y)
{
int t;
t=x;
x=y;
y=t;
}
</span>int main()
{
int a,b;
cin>>a>>b;
<span style="color:#ff0000;">myswap(a,b);
</span>	cout<<a<<" "<<b<<endl;
return 0;
}




#include<iostream>
using namespace std;
<span style="color:#ff0000;">void myswap(int *p1, int *p2)
{
int t;
t=*p1;
*p1=*p2;
*p2=t;
}
</span>int main()
{
int a,b;
cin>>a>>b;
<span style="color:#ff0000;">myswap(&a,&b);
</span>	cout<<a<<" "<<b<<endl;
return 0;
}
<img src="https://img-blog.csdn.net/20150907170858193" alt="" />
#include<iostream>
using namespace std;
<span style="color:#ff0000;">void myswap(int &x, int &y)
</span>{
int t;
t=x;
x=y;
y=t;
}
int main()
{
int a,b;
cin>>a>>b;
<span style="color:#ff0000;">myswap(a,b);
</span>	cout<<a<<" "<<b<<endl;
return 0;
}




 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: