| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 783 人关注过本帖
标题:函数的参数传递
取消只看楼主 加入收藏
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
快速回复:函数的参数传递
数据加载中...
 
   



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

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