int rats;

int & rodents = rats;

rats 和 rodents 可以互换,他们指向相同的值和内存单元。其实就是给rats取了别名rodents。

修改其中任意一个的值都将导致另外一个值的内容发生变化。

 

使用时需要注意,int & rodents = rats;     //这条语句必须一次性完成,也就是在声明时就需要初始化。

int rats;

int & rodents;

rodents = rat;    //这里会报错。

 

C++ 引用变量

C++ 引用变量

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2021-06-03
  • 2021-07-11
  • 2022-01-30
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
相关资源
相似解决方案