标题:函数的参数传递
取消只看楼主
elegant87
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2008-1-15
 问题点数:0 回复次数:0 
函数的参数传递
函数的参数传递。

先看一个例子:

#include<iostream>
using namespace std;
void swap(int a,int b);
int main()
{
int x=10, y=7;
cout<<x<<" "<<y<<endl;;
swap(x ,y);
cout<<x<<" "<<y<<endl;
return 0;
}
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
}

结果:10 7

           10 7


使用引用调用时:

#include<iostream>
using namespace std;
void swap(int&a,int&b);
int main()
{
int x=10, y=7;
cout<<x<<y;
swap(x ,y);
cout<<x<<y;
return 0;
}
void swap(int&a,int&b)
{
int temp;
temp=a;
a=b;
b=temp;
}

结果:10   7

           7      10

大家看看这是为什么呢?????
搜索更多相关主题的帖子: 函数 参数 
2008-01-15 15:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-197523-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.138251 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved