当前位置:网站首页>Left and right values

Left and right values

2022-06-23 04:48:00 Boundless also initial heart

C/C++ Variables that can be placed to the left of the assignment symbol in the language , Left values represent objects stored in computer memory , The left value is equivalent to the address value . Right value : When a symbol or constant is placed to the right of the operator , Just read their computers “ Right value ”, That is, the real value it represents , The right value is equivalent to the data value .

L-value and R-value basic information

C/C++ Variables that can be placed to the left of the assignment symbol in the language , That is, it has a corresponding storage unit that can be accessed by the user , And it can be changed by the user . Left values represent objects stored in computer memory , Instead of constants or calculated results . Or the left value represents a memory address value , And through this memory address , You can read and write to the memory ( Mainly can write ) operation ; That's why left values can be assigned . And the corresponding right value : When a symbol or constant is placed to the right of the operator , Just read their computers “ Right value ”, That is, the real value it represents . In a nutshell , The left value is equivalent to the address value , The right value is equivalent to the data value . The right value refers to a reference to a data stored in a memory address .

Examples

such as : int ia,ib;
ib=0;
ia=ib;
ad locum , First define ia,ib. Then on ib assignment , At this time, the computer takes ib Left value of , That is, the memory location represented by this symbol, that is, the memory address value , Computer access 0 The right value , That's the number 0; And then to ia The assignment is ib, At this time take ib The right value of is given to ia Left value of ;
So ,ib Left value of 、 The right value is based on his position ;
This is an interesting part of formal language .

Application attention

Left value right value translation :
L-value Medium L refer to Location, Represents addressable .Avalue (computer science)that has an address.
R-value Medium R refer to Read, Means to read .in computer science, a value that does not have an address in a computer language.
Left and right values are relative to assignment expressions . An lvalue is an expression that can appear to the left of an assignment expression . Lvalue expressions can be divided into read-write lvalues and read-only lvalues . A right value is an expression that can appear to the right of an assignment expression , It can be a temporary amount or a literal amount that doesn't occupy memory space , It can be a spatial entity with no write right . Such as
int a=3;
const int b=5;
a=b+2; //a It's left ,b+2 It's right value
b=a+2; // wrong !b Is a read-only lvalue but has no write rights , Cannot appear to the left of the assignment symbol
(a=4)+=28; //a=4 It's an lvalue expression ,28 It's right value ,+= For assignment operators
34=a+2; // wrong !34 The literal quantity can't be left value

原网站

版权声明
本文为[Boundless also initial heart]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230006250520.html