当前位置:网站首页>Summary of some problems about left value and right value [easy to understand]
Summary of some problems about left value and right value [easy to understand]
2022-07-25 14:09:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
stay C In language , We often encounter some small knowledge points that we usually feel will not make mistakes in how to use them , But when it is a little more difficult , Or change it a little , We will no longer use it so handy . The left value and the right value are exactly an example of such a perfect ten . After learning pointer knowledge , A high understanding of left and right values will no longer seem so boring .
This explanation looks a little silly , But I have to say :
Lvalues are those that can appear to the left of the assignment symbol , Right values are those that can appear to the right of the assignment symbol .
for example :a=b+25;
here ,a It's left , It identifies a point where the result value can be stored , in other words , He has a fixed space that he can control ,b+25 It's right value , Because he specified a value .
So can they exchange ?
for example :b+25=a;
The answer, of course, is no ;
Be careful , When the computer calculates b+25 Its result must be stored somewhere in the machine . But programmers have no way to predict where the results will be stored , There is no guarantee that the value of this expression will still exist in the original place next time . The result is b+25 Can't be an lvalue . Because he doesn't have a fixed mark .
however a It can be used as an R-value , Because each position includes a value .
So in summary :
The left value : We mainly use his space ;
Right value : We mainly use his value .
Literal constants cannot be lvalues .
In order to consolidate the theory learned above , In order to let us know more about what happened , Now let's discuss the following examples in depth :
When there's code :
char ch=‘a’;
char *cp=&ch;
Let's see what the following code means ? Can I do lvalue ? Can I make a right value ?
&ch; //&ch Is the address constant , Only lvalue , Can't do right value ;
cp; //cp It's a variable , Existing storage space , It's worth it again , So both left and right values can be done ;
&cp; //&cp Is the address constant , Can only do right value , You can't be left-handed .
*cp+1; // Its operation order is , Will now cp Quoting , then cp The value of the add 1, So it's a constant ( In the subject , He expressed to a+1, That's the character b), Can only do right value , Cannot lvalue ;
*(cp+1); // The operation here means ch Then a space ( Read cp The content of the next space ), You can do lvalue , You can also do the right value ;
++cp; // This is for ch My address plus 1, That is to add 1, You can do the right value , You can't do lvalue ;
cp++; // Reason and ++cp For the same reason ;
*++cp; // Add it first , In dereference , According to the ch The next space ( Read the contents of the next space ), You can do lvalue , You can also do the right value ;
*cp++; // For the same reason ;
(*cp)++; // It means that you will ch My address plus 1, Is a constant , You can't do lvalue , But you can do the right value ;
++*++cp; // Said to ch The prefix of the next space address ++, Is a constant , You can't do lvalue , But you can do the right value ;
++*cp++; // Said to ch The space address of is prefixed ++, In the back ++, Is a constant , You can't be left-handed , But you can do the right value .
Okay , Come here first
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/127557.html Link to the original text :https://javaforall.cn
边栏推荐
- From fish eye to look around to multi task King bombing -- a review of Valeo's classic articles on visual depth estimation (from fisheyedistancenet to omnidet) (Part I)
- That day, I installed a database for my sister... Just help her sort out another shortcut
- Wangeditor rich text editor
- Tensorflow2 installation quick pit avoidance summary
- Tm1638 LED digital display module Arduino drive code
- [force deduction] 1030. Arrange matrix cells in distance order
- Arduino code of key state machine for realizing single, double click, long press and other functions with esp32 timed interrupt
- 2271. 毯子覆盖的最多白色砖块数 ●●
- Okaleido ecological core equity Oka, all in fusion mining mode
- CTS测试介绍(面试怎么介绍接口测试)
猜你喜欢

Setting of parameter configuration tool for wireless vibrating wire collector

Amd epyc 9664 flagship specification exposure: 96 core 192 threads 480MB cache 3.8ghz frequency

Brush questions - Luogu -p1152 happy jump

Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output

2271. 毯子覆盖的最多白色砖块数 ●●

What problems should SEOER pay attention to when baidu searches and attacks pirated websites?

Interpretation of featdepth self-monitoring model for monocular depth estimation (Part I) -- paper understanding and core source code analysis

Internal error of LabVIEW

Deep understanding of pytorch distributed parallel processing tool DDP -- starting from bugs in engineering practice

Brush questions - Luogu -p1047 trees outside the school gate
随机推荐
2271. Maximum number of white bricks covered by blanket ●●
Brush questions - Luogu -p1151 sub number integer
What problems should SEOER pay attention to when baidu searches and attacks pirated websites?
From fish eye to look around to multi task King bombing -- a review of Valeo's classic articles on visual depth estimation (from fisheyedistancenet to omnidet) (Part 2)
Brush questions - Luogu -p1047 trees outside the school gate
Arduino code of key state machine for realizing single, double click, long press and other functions with esp32 timed interrupt
Day1:三种语言暴刷牛客130题
Alibaba mqtt IOT platform "cloud product circulation" practice - the two esp32 achieve remote interoperability through the IOT platform
It is predicted that 2021 will accelerate the achievement of super automation beyond RPA
苹果手机端同步不成功,退出登录,结果再也登录不了
Apple failed to synchronize on its mobile terminal, so it exited the login. As a result, it could not log in again
Common problems in the use of wireless vibrating wire acquisition instrument
dp-851
Mongodb source code deployment and configuration
【学习记录】plt.show()闪退解决方法
From fish eye to look around to multi task King bombing -- a review of Valeo's classic articles on visual depth estimation (from fisheyedistancenet to omnidet) (Part I)
Realize a family security and environmental monitoring system (I)
Business analysis report and data visualization report of CDA level1 knowledge point summary
手把手教你申请SSL证书
Dr. Berkeley's "machine learning engineering" big truth; AI vice president '2022 ml job market' analysis; Large list of semiconductor start-ups; Large scale video face attribute data set; Cutting edge