c++基础再走一波
9 引用是变量的别名(不能只有别名)
基本数据类型的引用
#include<iostream>
using namespace std;
int main(void)
{
int a = 3;
int &b = a; //引用必须初始化
b = 10;
cout<<a<<endl;
system("pause"); //屏幕停一会儿
return 0;
}
输出结果:10
结构体类型的引用
#include<iostream>
using namespace std;
typedef struct
{
int x;
int y;
}Coor;
int main(void)
{
Coor c1;
Coor &c = c1;
c.x = 10;
c.y = 20;
cout<<c1.x<<c1.y;
system("pause");
return 0;