Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Difference between left and right values
Difference between left and right values
Left value and right value

In common parlance, it is. Bounded by the assignment symbol =, = left is the left value, = right is the right value. For example: (1) int b = 3; (2)int a = b; Code in line (2), where a is the value on the left and b is the value on the right.

At a deeper level, the L of L-value can be understood as Location, which means location and address. Understand r of R-value as Read, which means reading data. Computer data is now stored in memory. Memory has two very basic attributes: memory address and data stored in memory. Imagine an identical box. Each box has a number to distinguish which box it is and what can be put in it. The memory address is equivalent to the serial number of the box, and the data in the memory is equivalent to what is put in the box.

After the variable name is compiled, it will be mapped to a memory address. Look at the meaning of a = b, in fact, it is to put the "data in the memory of address b" into the memory of address a.

Chinese name

Left and right values

Foreign name

Left and right values

quick

navigate by water/air

Case enumeration

Matters needing attention in application

Basic information of left and right values

In C/C++ language, variables that can be placed to the left of assignment symbols have corresponding storage units, which users can access and change the number of their values. Left values represent objects stored in computer memory, not constants or calculation results. Or the left value represents a memory address value, through which memory can be read and written (mainly writable); This is why the left value can be assigned. Corresponding right value: When a symbol or constant is placed on the right side of an operator, the computer reads their "right value", that is, the real value it represents. Simply put, the left value is equivalent to the address value and the right value is equivalent to the data value. The right value refers to the reference to the data stored in the memory address.

Case enumeration

For example: int ia, IB;

IB = 0;

ia = ib

Here, define ia and ib first. Then assign a value to ib. At this time, the computer takes the left value of ib, that is, the memory location represented by this symbol, that is, the memory address value, and the computer takes the right value of 0, that is, the value of 0; Then assign the value of ia to ib, and at this time take the right value of ib as the left value of ia;

So the left and right values of ib are based on his position;

This is also an interesting part of the formal language.

Matters needing attention in application

Left and right value conversion:

L in L-value refers to location, which means addressable. Addressed values (computer science).

R in R-value means Read, which means readable. In computer science, a value that has no address in computer language.

The left and right values are relative to the assignment expression. A left value is an expression that can appear on the left side of an assignment expression. Left-valued expressions can be divided into read-write left values and read-only left values. A right value is an expression that can appear on the right side of an assignment expression. It can be a temporary or literal amount that does not occupy memory space, and it can be a space entity without write permission. such as

int a = 3;

const int b = 5;

a = b+2; //a is the left value, and b+2 is the right value.

b = a+2; //Wrong! B is a read-only left value, but it has no write permission and cannot appear on the left side of the assignment symbol.

(a = 4)+= 28; //a=4 is a left-valued expression, 28 is a right-valued expression, and+= is an assignment operator.

34 = a+2; //Wrong! 34 is a literal quantity, so you can't take a value from the left.