c++中左值的含义

<<cpp primer plus 6th edition>>中的原文(Chapter 8 Adventures in Functions):

What is an lvalue? An argument that’s an lvalue is a data object that can be referenced
by address. For example, a variable, an array element, a structure member, a reference, and
a dereferenced pointer are lvalues. Non-lvalues include literal constants (aside from quoted
strings, which are represented by their addresses) and expressions with multiple terms.The
term lvalue in C originally meant entities that could appear on the left side of an assignment
statement, but that was before the const keyword was introduced. Now both a regular
variable and a const variable would be considered lvalues because both can be
accessed by address. But the regular variable can be further characterized as being a
modifiable lvalue and the const variable as a non-modifiable lvalue.

在第五版对应章节中中作者解释的比较简单,第六版进行了更详细的解释。第五版原文如下:

An argument that’s an lvalue is a data object that can be referenced. For example, a variable,
an array element, a structure member, a reference, and a dereferenced pointer are lvalues.
Non-lvalues include literal constants and expressions with multiple terms.

第五版已有中文版,第六版中文版貌似亚马逊上本月(2013.07月)已上架。

另外c++11还增加了右值(rvalue)的概念,声明方式为:int && num=10;使用&&来表示。

原文链接: https://www.cnblogs.com/argb/p/3221224.html

欢迎关注

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

    c++中左值的含义

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

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

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

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

(0)
上一篇 2023年2月10日 上午4:19
下一篇 2023年2月10日 上午4:19

相关推荐