#include <iostream> using namespace std; int main( ) { int x = 10; int& ref = x; ref = 20; cout << "x= " << x << endl; x = 30; cout << "ref=" << ref << endl;
输出结果x =1, ref =2
ref是x的别名,指向同一存储空间
一个修改,二者一起修改
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题