Definitions of lvalue and rvalue in C and C ++

Source: Internet
Author: User
Definition of lvalue and rvalue in C and C ++-Linux general technology-Linux programming and kernel information. The following is a detailed description. Author: nathanxu

When reading the GCC documentation, I saw the lvalue word and checked Kingsoft's definition as the left value of lvalue [count. Because I have heard of this word in the course about compilation principles, and I have not thought much about it. However, after reading the GCC documentation, you cannot understand what the whole article is about. The problem lies in the understanding of the meaning of the "Left value" in the word "lvalue. Looking for a M-W dictionary, but told that there is no such word. As a result, google does call it the left value in many places, and I still have no choice. Finally, find the exact meaning of the word on the About Site of an encyclopedia. The post is as follows:
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. this is contrasted with a constant. A constant has some data value, that is an rvalue. but, it cannot be written. 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.

In this section, I understand that l in lvalue actually refers to the storage address attribute that represents the value, and r in another relative word rvalue refers to the read attribute, it has nothing to do with left and right. Kingsoft is really a shit.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.