本文介绍了什么是左值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在K& R中,他们说: 对象是一个命名的存储区域;左值是表达式 是指一个对象。 C ++中的这些概念怎么样? `C ++编程语言''也有类似的解释,但是, 可能过于简短。 有人能给我更详细的解释吗?或者给一些推荐 关于它? 谢谢。 - Hongzheng Wang 解决方案 这最近在NG中有所涉及。 " lvalue" ;是左手边值的缩写。 (作业)。 非左值表达式的例子: (3 + 3)//你不能分配3 + 3! (" str")//不能指定字符串 这些是左值 : int var; var = 3 + 3; // var是一个左值 *((char *)& var)=" str" [2]; // *((char *)& var) int& varref = var; varref = 1 [" str"]; // varref也是左值 int& func(){return var; } func()= 2; // func返回一个引用(左值) C ++中的,字符串文字是l值。 解释l值是可以在 ''='''的右侧在C ++中不是一个很好的解释。有许多l值的例子 无法分配给r值和可分配给的值: const int i = 5; i = 2; //错误L值''我'不可修改 struct C { C& operator =(int); }; C()= 5; //确定分配给r值C(); - Dag Henriksson Hongzheng Wang < WA ****** @ mails.tsinghua.edu.cn>在消息中写道 news:br ********** @ news.yaako.com ... 从comp.std.c读取这个帖子++ - http://makeashorterlink.com/?H23F161C6 HTH, J.Schafer In K&R, they said:An object is a named region of storage; an lvalue is an expressionrefer to an object.How about these concept in C++?`The C++ Programming Language'' has a similar explanation, however, itmay be too brief.Can anyone give me a more detailed explanation? Or give some referrencesabout it?Thank you.--Hongzheng Wang 解决方案This was covered in the NG recently."lvalue" is short for "left hand side value" (of an assignment).examples of non-lvalue expressions:( 3 + 3 ) // you can''t assign 3 + 3 !( "str" )// string can''t be assigned eitherThese are "lvalues" :int var;var = 3 + 3;// var is an lvalue* ( ( char * ) & var ) = "str"[2]; // * ((char *)&var) tooint & varref = var;varref = 1["str"]; // varref is also an lvalueint & func() { return var; }func() = 2; // func returns a reference (lvalue)in C++, string literals are l-values.The explanation "l-values are something that can be at the right side of an''=''" is not a good explanation in C++. There are many examples of l-valuesthat cannot be assigned to and r-values that can be assigned to:const int i = 5;i = 2; // error. L-value ''i'' not modifiablestruct C{C& operator=(int);};C() = 5; // OK to assign to r-value C();--Dag HenrikssonRead this thread from comp.std.c++- http://makeashorterlink.com/?H23F161C6HTH,J.Schafer 这篇关于什么是左值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-03 18:12