`
weihe6666
  • 浏览: 430920 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

C++里面的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中的l其实指的表示该值的存储地址属性,而另外一个相对的词rvalue值中的r指的是read的属性,和左右根本没有任何关系。
分享到:
评论

相关推荐

    理解C++ lvalue与rvalue

    而左值(lvalue)和右值(rvalue)的概念,本质上,是理解“程序员可以放心使用的变量”。  空泛的讨论先到这里,先看一段会报错的代码: #include using std::cout; using std::endl; int foo(int &a) { ...

    Mastering the C++17 .pdf

    The C++ language has a long history, dating back to the 1980s. Recently it has undergone a renaissance, ...class and function templates, the difference between lvalue and rvalue references, and so on.

    C++11中value category(值类别)及move semantics(移动语义)的介绍

    C++11之前value categories只有两类,lvalue和rvalue,在C++11之后出现了新的value categories,即prvalue, glvalue, xvalue。不理解value categories可能会让我们遇到一些坑时不知怎么去修改,所以理解value ...

    [Visual.C++.2010入门经典(第5版)].Ivor.Horton.part1

    2.10 lvalue和rvalue 73 2.11 了解存储时间和作用域 74 2.11.1 自动变量 74 2.11.2 决定变量声明的位置 76 2.11.3 全局变量 77 2.11.4 静态变量 80 2.12 名称空间 80 2.12.1 声明名称空间 81 2.12.2 多个名称空间 82...

    visualC++2010入门经典源代码

    2.10 lvalue和rvalue 73 2.11 了解存储时间和作用域 74 2.11.1 自动变量 74 2.11.2 决定变量声明的位置 76 2.11.3 全局变量 77 2.11.4 静态变量 80 2.12 名称空间 80 2.12.1 声明名称空间 81 2.12.2 多个...

    Visual C++ 2010入门经典(第5版)--源代码及课后练习答案

    2.10 lvalue和rvalue 73 2.11 了解存储时间和作用域 74 2.11.1 自动变量 74 2.11.2 决定变量声明的位置 76 2.11.3 全局变量 77 2.11.4 静态变量 80 2.12 名称空间 80 2.12.1 声明名称空间 81 2.12.2 多个...

    C++中的左值和右值

    在C/C++中,左值(lvalue)和右值(rvalue)是用于规定表达式(expression)的性质。C++中表达式要不然是左值,要不然是右值。  这两个概念在C语言中比较容易理解:左值能放在赋值语句的左边,右值不能。但是当来到C++时...

    C++11右值引用和转发型引用教程详解

    为了解决移动语义及完美转发问题,C++11标准引入了右值引用(rvalue reference)这一重要的新概念。右值引用采用T&&这一语法形式,比传统的引用T&(如今被称作左值引用 lvalue reference)多一个&。 如果把经由T&&...

    lvalue

    lvalue

    c++11 Value Terminology

    c++11 Value Terminology

    Google C++ International Standard.pdf

    7.1 Lvalue-to-rvalue conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 7.2 Array-to-pointer conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

    C++中的delete不会将操作数置0

    考虑一下: delete p; // ... delete p; 如果在…部分没有涉及到p 的话,那么第二个“delete p;”将是一个严重的错误,因为C++的...一个原因是,delete 的操作数并不需要一个左值(lvalue)。考虑一下: dele

    lvalues:经典和量子程序中的LValue

    lvalues:经典和量子程序中的LValue

    insert_const_lvalue.rar_return

    wfc_util_qcom_check_config((unsigned char )macAddress) return 0 .

    C++ 标准 ISO 14882-2011

    4.1 Lvalue-to-rvalue conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 4.2 Array-to-pointer conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

    sonsole-lvalue.rar_3AJW_tobaccoujz

    学习开发opcclient的好例子,结构清晰

    insert_const_lvalue.rar_V2 _llvm

    The LLVM Compiler Infrastructure Kernel Device Driver for linux v2.13.6.

    modern-cpp-cheatsheet:有关现代C ++最佳实践的备忘单(摘自有效的现代C ++)

    lvalue-ref(erence) :对通常由&表示的左值类型的引用,例如auto& lvalue_ref = x; rvalue-ref(erence) :对通常由&&表示的右值类型的引用,例如auto&& rvalue_ref = 10; 复制操作:使用拷贝构造函数和拷贝...

    C++出错提示英汉对照表

    Lvalue required ---------------------------需要逻辑值0或非0值 Macro argument syntax error -------------------宏参数语法错误 Macro expansion too long ----------------------宏的扩展以后太长 ...

    C++11特性小结之decltype、类内初始化、列表初始化返回值

    若e是一个左值(lvalue,即“可寻址值”),则decltype(e)将返回T& 若e是一个临终值(xvalue),则返回值为T&& 若e是一个纯右值(prvalue),则返回值为T decltype()不会执行括号内的表达式,decltype返回的类型...

Global site tag (gtag.js) - Google Analytics