You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
对于第二个不同点, 网上举了很多例子, 比如:
![image](https://user-images.githubusercontent.com/25657798/59015446-94c2ff00-8871-11e9-9669-aebec95c769b.png)
最开始被例子中的注释
// error,引用不能换了
给误导, 以为这样写的话, 编译器就会报错而无法运行, 其实不然.引用不能指向另外一个对象的意思是, 如果一个引用初始化时指向对象a, 那么对该引用再次赋值成对象b就相当于给对象a再次赋值, 其值为对象b的地址对应的值, 而不是将该引用指向对象b
此时执行
ref_var_a = var_b;
, 相当于执行var_a = var_b;
通过下面这段代码和output会更加明显.对应的output如下:
可以看出:
ref_var_a
的地址在执行ref_var_a = var_b
前后始终没变: 0015F8A8var_a
的地址对应的值在ref_var_a = var_b
之后变成了var_b
的地址对应的值: 2var_a
的值发生了变化, 而ref_var_a
指向var_a
, 所以之后ref_var_a
的值也变成了2The text was updated successfully, but these errors were encountered: