23 一般引用的用法
(1)代码
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 int main(int argc, char* argv[]) 5 { 6 int a = 10; 7 int b = 20; 8 int &rn = a;//声明rn为变量a的引用 9 int equal; 10 11 rn = b;//rn是a的别名 也就是b赋值给rn实际上就是修改了a的值 引用不用开辟内存单元 12 cout << "a=" << a << endl;//10 13 cout << "b=" << b << endl;//20 14 15 rn = 100; 16 cout << "a=" << a << endl;//100 17 cout << "b=" << b<< endl;//20 18 19 equal = (&a == &rn) ? 1 : 0; 20 cout << "equal=" << equal << endl;//1 21 22 getchar(); 23 24 return 0; 25 26 }