C++中的引用-引用的基本语法和注意事项

  • 引用

 

别名和原名操作同一块内存

  • 引用注意事项

 

 

点击查看代码
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int a = 10;

	//1、引用必须初始化
	//int &b; //错误,必须初始化

	int &b = a;

	//2、引用在初始化之后,不可以改变
	int c = 20;

	b = c; //赋值操作,而不是更改引用

	cout << "a = " << a << endl;//20
	cout << "b = " << b << endl;
	cout << "c = " << c << endl;

	system("pause");

	return 0;
}

 

posted @ 2021-07-22 16:12  毋纵年华  阅读(104)  评论(0)    收藏  举报