Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept of left value and right value in C language

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the concept of left value and right value of c language". The explanation in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian and go deep into it slowly to study and learn "what is the concept of left value and right value of c language" together!

L-value and R-value

expounded

An assignment expression can be divided into lvaule and rvaule, so what are lvaule and rvaule? What is the meaning of array names as left-right values?

The lvalue estimate is derived from the left value. In an assignment statement, the lvalue = rvalue; position is on the left. values that can be modified.

The rvalue estimate is derived from the right value. On the right side of the assignment statement is a read-only, non-modifiable value.

An l-value is an expression that can be assigned, i.e. the expression to the left of the assignment symbol. From this, we know that the rvalue is the expression that points to the right of the current assignment. Each assignment statement has an l-value and an r-value.

(1)The left value must be a variable. The left value must be a storable variable in memory, not a constant or

The expression. For example, the following is the correct left value

int i;

int *p;

i=5;

*p=3;

i is an integer variable with a corresponding storage location in memory. Therefore, in the statement i=5, i can be used as an left value. In the statement *p=3, *p indicates the memory region p points to, so *p is an lvalue. The following examples are not LVs.

#define PRICE 10

int i,j;

PRICE=20;

(i+j)=10;

In the above code, PRICE is a constant value that cannot be changed because a constant does not represent a storable location in memory, and (i+j) is an expression that does not represent a storable location in memory. So the left values of both assignments are incorrect.

(2)The rvalue can be a constant or an expression, for example

#define PRICE 10

int i,j;

int *p:

i=5;

j=i+5

*p=PRICE;

(3)Assignment statements must have an l-value and an r-value. An assignment statement must have an l-value and an r-value, otherwise it will not compile.

Meaning of array names as left-right values:

When the array name is an lvalue, it is wrong. The compiler will think that the name of the array as an lvalue represents the first address of the first element of the array, but the block of memory at the beginning of this address is a whole, and can only access one element of the array, but not the entire array, so you can use a[3] as an lvalue, not a.

The array name represents the first address of the array, so when the array name is an rvalue, the first address of the array is assigned to the variable to the left of the assignment.

In summary, array names cannot be used as l-values, while elements in arrays can be used as l-values. Because each element in an array can also be thought of as a variable, it has a corresponding storage location in memory.

Thank you for reading, the above is "c language left value and right value of the concept is what" the content, after the study of this article, I believe that we have a deeper understanding of the concept of c language left value and right value, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report