实例:
#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;
}
指针是间接访问,引用时直接访问。