reference in C++

本文解释了C++中引用的概念,将其比喻为一种特殊的指针,这种指针自动解除引用且必须初始化。文章探讨了引用如何作为指向其他变量的别名,并强调了其在语法上的简洁性。

A reference(&) is like a constant pointer that is automatically dereferenced.
Any reference must be tied to someone else's piece of storage.When u access a reference,
u're accessing that storage.
Thus,the easiest way to think about a reference is as a fancy pointer.The advantage of this
pointer is that u never have to wonder whether it's been initialized(the compiler enforces
it) and how to dereference it(the compiler does it).
Ofcourse,u can do the same thing by passing a pointer,but reference has much cleaner syntax.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值