• 3683阅读
  • 2回复

Question6.7:How can an array be an lvalue,if you can't assign to it? [复制链接]

上一主题 下一主题
离线那个谁
 

只看楼主 倒序阅读 使用道具 楼主  发表于: 2013-07-09
— 本帖被 tyrone2497谁 执行加亮操作(2013-07-16) —
Q: How can an array be an lvalue, if you can't assign to it?

A: The term ``lvalue'' doesn't quite mean ``something you can assign to''; a better definition is ``something that has a location (in memory).'' The ANSI/ISO C Standard goes on to define a ``modifiable lvalue''; an array is not a modifiable lvalue. See also question 6.5.
离线那个谁

只看该作者 沙发  发表于: 2013-07-09
问题:如果你不能对他们赋值,那么数组成为一个左值(我查找了定义,C语言中指的是可以放在赋值符号左边的变量,其实这句话是不正确的理解。我在下面给出原话http://blog.csdn.net/xbt746/article/details/6170799)?
回答:术语“左值”并不是说“你可以对它们赋值”,一个更好的定义是“在内存中有一个位置”。ANSI/ISO C标准将继续定义一个“可修改的左值”;一个数组并不是一个可修改的左值。参考问题6.5。
1条评分小风币+1
果子 小风币 +1 +1 2013-07-09
离线那个谁

只看该作者 板凳  发表于: 2013-07-09
An object is a region of storage that can be examined and stored into. An lvalue is an expression that refers to such an object. An lvalue does not necessarily permit modification of the object it designates. For example, a const object is an lvalue that cannot be modified. The term modifiable lvalue is used to emphasize that the lvalue allows the designated object to be changed as well as examined. The following object types are lvalues, but not modifiable lvalues:
•An array type
•An incomplete type
•A const-qualified type
•An object is a structure or union type and one of its members has a const-qualified type
Because these lvalues are not modifiable, they cannot appear on the left side of an assignment statement.
一个对象(object)是一个能够被检查和存储数据的存储区域。一个左值就是与这种对象相关的一个表达式。一个左值并不一定是一个可以允许修改的指定的对象。例如:一个const的对象就是一个不可被修改的左值。可修改的左值这个术语是用来强调左值允许指定的对象在被检查的同时也可以被修改。下面的对象类型就是左值,并且是不可修改的左值:
1、一个数组类型
2、不完全的类型
3、一个被const修饰的类型
4、一个结构体或者联合中有被const修饰的类型的对象
因为这些左值都是不可被改变的,他们也不能出现在赋值语句的左边。
快速回复
限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
上一个 下一个