您的位置:首页 > 其它

基础知识-通过引用来传递函数参数(直接访问函数参数)

2010-09-15 09:50 441 查看
实例:

#include "stdafx.h"
#include "iostream.h"
void sum(float &ra ,float &rb)//别名直接引用方式
{
float x;
x=ra;
ra=rb;
rb=x;
}

int main()
{
float a, b;
a=2;
b=3;
cout<<"转换前a的值为:"<<a<<endl;
cout<<"转换前b的值为:"<<b<<endl;
sum(a,b);
cout<<"转换后a的值为:"<<a<<endl;
cout<<"转换后b的值为:"<<b<<endl;
return 0;
}

指针是间接访问,引用时直接访问。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: