int main() { int a = 10; //int &b; /* 引用必须初始化 */ int &b = a; /* 一旦初始化,不可更改 */ int c = 12; b = 12; /* 赋值 */ cout << "a: " << a << endl; cout << "b: " << b << endl; cout << "c: " << c << endl; return 0; }
a: 12 b: 12 c: 12
int main() { int a = 10; //int &b; /* 引用必须初始化 */ int &b = a; /* 一旦初始化,不可更改 */ int c = 12; b = 12; /* 赋值 */ cout << "a: " << a << endl; cout << "b: " << b << endl; cout << "c: " << c << endl; return 0; }
a: 12 b: 12 c: 12