4.3-引用赋值.cpp

来自「Visual C++的课件」· C++ 代码 · 共 27 行

CPP
27
字号
//Listing 9.3
//Reassigning a reference

#include <iostream.h>

int main()
{
	int  intOne;
	int &rSomeRef = intOne;

	intOne = 5;
	cout << "intOne:\t" << intOne << endl;
	cout << "rSomeRef:\t" << rSomeRef << endl;
	cout << "&intOne:\t"  << &intOne << endl;
	cout << "&rSomeRef:\t" << &rSomeRef << endl;

	int intTwo = 8;
	rSomeRef = intTwo;  // not what you think!
	cout << "\nintOne:\t" << intOne << endl;
	cout << "intTwo:\t" << intTwo << endl;
	cout << "rSomeRef:\t" << rSomeRef << endl;
	cout << "&intOne:\t"  << &intOne << endl;
	cout << "&intTwo:\t"  << &intTwo << endl;
	cout << "&rSomeRef:\t" << &rSomeRef << endl;
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?