C++ values 和rvalues

C++左值和右值是一个不容易理解的概念,而且经常由于使用不正确而出现错误。
这里看到一个定义:
An lvalue (locator value) represents an object that occupies some identifiable location in memory (i.e. has an address).
rvalues are defined by exclusion, by saying that every expression is either an lvalue or an rvalue. Therefore, from the above definition of lvalue, an rvalue is an expression that does not represent an object occupying some identifiable location in memory.
 
左值变量与右值变量之间的转换
除了数组、不完整类型和函数,所有左值变量都能转换为右值。反之,则不行。但解引用操作符*是一个意外,能将右值变为左值,如*(p+1) = 10, p+1是右值,但*(p+1)是左值。 同时,&操作符也能将左值变为右值。

Leave a Reply

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