C++离港篇
作者:互联网
4.0 C++语言引用
也就是变量的别名
基本数据类型的引用
#include <iostream> using namespace std; int main(void) { int a = 3; int &b = a; //引用必须初始化 b = 10; cout << a << endl; return 0; }
结构体类型的引用
#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 << endl; return 0; }
指针类型的引用
#include <iostream> using namespace std; int main(void) { int a = 10; int *p = &a; int *&q = p; *q = 20; cout << a << endl; return 0; }
引用做函数参数
标签:Coor,cout,int,namespace,C++,引用,main,离港 来源: https://www.cnblogs.com/pxxfxxxx/p/11057780.html