左值? [英] Lvalue?
问题描述
嗨朋友们,
我在之前的帖子中读过Lvalue并用Google搜索,但我不是
完全理解它。
有一个小疑问。
int a;
a = 20; //这里是Lvalue
但是
以下示例中的左值是多少。
struct Node
{
int a;
int b;
};
struct节点tempNode1,tempNode2;
tempNode1.a = 2;
tempNode1.b = 3;
tempNode2 = tempNode1; //在这种情况下Lvalue是多少。
谢谢......
Hi friends,
I read about Lvalue in previous posting and Googled it but I''m not
understood it completely.
There is a small doubt.
int a;
a=20; // here a is Lvalue
But
What is the Lvalue in the following example.
struct Node
{
int a;
int b;
};
struct Node tempNode1, tempNode2;
tempNode1.a=2;
tempNode1.b=3;
tempNode2=tempNode1; // What is the Lvalue in this case.
Thanks...
推荐答案
the_init:
the_init:
int a;
a = 20; //这里是左值
int a;
a=20; // here a is Lvalue
正确。
Correct.
但是
以下示例中的左值是多少。
struct Node
{
int a;
int b;
};
struct Node tempNode1,tempNode2;
tempNode1.a = 2;
tempNode1.b = 3;
tempNode2 = tempNode1;
But
What is the Lvalue in the following example.
struct Node
{
int a;
int b;
};
struct Node tempNode1, tempNode2;
tempNode1.a=2;
tempNode1.b=3;
tempNode2=tempNode1;
所有这些都是L值。经验法则是:如果它可以出现在赋值语句的
左侧,则它是一个L值。
我们最熟悉的L值是简单的对象:
int a; a = 5;
双k; k = 4;
,但我们也可以从其他地方获得L值,例如:
* p = 5;
-
Frederick Gotham
All of them are L-values. The rule of thumb is: "If it can appear on the
left-hand side of an assignment statement, then it is an L-value".
The L-values we''re most familiar with are simple objects:
int a; a = 5;
double k; k = 4;
, but we can also obtain L-values from other places, e.g.:
*p = 5;
--
Frederick Gotham
" the_init" < th ****** @ gmail.comwrites:
"the_init" <th******@gmail.comwrites:
我在之前的帖子中读到了Lvalue并用Google搜索了但是我不是
完全理解。
有一个小疑问。
int a;
a = 20; //这里是Lvalue
但是
以下示例中的左值是多少。
I read about Lvalue in previous posting and Googled it but I''m not
understood it completely.
There is a small doubt.
int a;
a=20; // here a is Lvalue
But
What is the Lvalue in the following example.
* *左值是什么意思?表达式或语句中不一定有一个单独的
左值;可能有多个左值,
或者可能有多个左值。
What do you mean by *the* lvalue? There isn''t necessarily a single
lvalue in an expression or statement; there could be multiple lvalues,
or there could be multiple lvalues.
struct Node
{
int a;
int b;
};
struct Node tempNode1,tempNode2;
tempNode1.a = 2;
tempNode1.b = 3;
tempNode2 = tempNode1; //在这种情况下,左值是多少?
struct Node
{
int a;
int b;
};
struct Node tempNode1, tempNode2;
tempNode1.a=2;
tempNode1.b=3;
tempNode2=tempNode1; // What is the Lvalue in this case.
左值是一个表达式(可能)指定一个对象。
某些表达式上下文需要一个左值;别人不这样做。分配表达式的左侧
手边需要一个左值(这是'
名称"'左右'来自;'''代表"左")。在
分配
tempNode2 = tempNode1;
tempNode1和tempNode2碰巧都是左值,因为它们
指定对象,但只有tempNode2用于
需要左值的上下文。
-
Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net / ~kst>
圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>
我们必须做点什么。这是事情。因此,我们必须这样做。
An lvalue is an expression that (potentially) designates an object.
Some expression contexts require an lvalue; others do not. The left
hand side of an assignment expression requires an lvalue (that''s where
the name "lvalue" comes from; the ''l'' stands for "left"). In the
assignment
tempNode2 = tempNode1;
both tempNode1 and tempNode2 happen to be lvalues, since they both
designate objects, but only tempNode2 is used in a context that
requires an lvalue.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Frederick Gotham写道:
Frederick Gotham wrote:
...
所有这些都是L值。经验法则是:如果它可以出现在赋值语句的
左侧,则它是一个L值。
.. 。
...
All of them are L-values. The rule of thumb is: "If it can appear on the
left-hand side of an assignment statement, then it is an L-value".
...
不,实际上。拇指的规则是:如果你可以对它应用一元''&'',
那么它就是左值。这也不是绝对准确的(特别是如果
被视为然后只有那时规则),但更接近
"赋值的事实基"版本。
-
祝你好运,
Andrey Tarasevich
No, actually. The rule of the thumb is: "If you can apply the unary ''&'' to it,
then it is an Lvalue". This also isn''t absolutely accurate (especially if
treated as "then and only then" rule), but much closer to the truth that the
"assignment-based" version.
--
Best regards,
Andrey Tarasevich
这篇关于左值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!