C++ values 和rvalues

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 *