引用

引用的本质就是指针常量。

设置了引用变量,编译器会自动把该变量编译为指针常量。

因为指针常量必须要初始化,解释了为什么引用必须要初始化。且指针常量不允许指向其他变量,引用也是。

int tmp = 10;
int& a = tmp;        //int* const a = &tmp;
a = 20;              //*a = 20;

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top