C和C++里面的lvalue 和 rvalue的释义

在看GCC的文档的时候,看到一个词lvalue,查了金山词霸其释义为 lvalue [计] 左值。因为的确在介绍编译原理的课程中听过这个词,大致知道其意思就没有多想。但是看完GCC文档的这个篇幅,都无法明白全篇在说什么。问题还是出在了lvalue这个词的“左值”是什么意思的理解上了。再找M-W字典,却告知没有这个词。于是google了一把,的确很多地方都称其为左值,我仍然不得要领。最后在一个百科网站About Site上找到该词的准确释义,摘贴如下:
Definition: C and C++ have the notion of lvalues and rvalues associated with variables and constants. The rvalue is the data value of the variable, that is, what information it contains. The "r" in rvalue can be thought of as "read" value. A variable also has an associated lvalue. The "l" in lvalue can be though of as location, meaning that a variable has a location that data or information can be put into. This is contrasted with a constant. A constant has some data value, that is an rvalue. But, it cannot be written to. It does not have an lvalue.

Another view of these terms is that objects with an rvalue, namely a variable or a constant can appear on the right hand side of a statement. They have some data value that can be manipulated. Only objects with an lvalue, such as variable, can appear on the left hand side of a statement. An object must be addressable to store a value.

Here are two examples.

int x;

x = 5; // This is fine, 5 is an rvalue, x can be an lvalue.
5 = x; // This is illegal. A literal constant such as 5 is not
      // addressable. It cannot be a lvalue.
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值