左值lvalue , rvalue

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.

说白了,lvalue指的是具有地址的,可以被赋予值的,rvalue是指可读取值得。lvalue即表示可以装东西的盒子,rvalue即盒子里的内容。一般是lvalue的同时也是rvalue,因为其既可以放东西,也可以取东西。而rvalue则不是这样。

原文链接: https://www.cnblogs.com/qytan36/archive/2010/05/26/1744803.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    左值lvalue , rvalue

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/11201

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月7日 上午12:55
下一篇 2023年2月7日 上午12:56

相关推荐