左值 [英] Lvalue

查看:76
本文介绍了左值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< stdio.h>

int main(无效)

{

int a = 1;

int b = 2;

int c = 0;

c =(a + b)++;

printf(" %d",c);

返回0;

}


对于上述程序,我得到错误,因为需要Lvalue 。我编译在

Turbo C / C ++编译器中。


任何人都可以解释为什么错误以及如何消除错误。


非常感谢。


问候,

Raghu

#include<stdio.h>
int main(void)
{
int a=1;
int b=2;
int c=0;
c=(a+b)++;
printf("%d",c);
return 0;
}

For the above program I got the error as Lvalue required.I compiled in
Turbo C/C++ compiler.

Can anyone please explain why the error is and how to eliminate it .

Thanks a lot.

Regards,
Raghu

推荐答案

raghu说:
raghu said:

#include< stdio.h>

int main(void)

{

int a = 1;

int b = 2;

int c = 0;

c =(a + b)++;

printf("%d",c);

返回0;

}


对于上面的程序,我得到了Lvalue所需的错误。
#include<stdio.h>
int main(void)
{
int a=1;
int b=2;
int c=0;
c=(a+b)++;
printf("%d",c);
return 0;
}

For the above program I got the error as Lvalue required.



这是对的,是的。 ++会影响对象的值。任意表达

不行。

That''s right, yes. ++ affects the value of an object. Arbitrary expressions
won''t do.


任何人都可以解释为什么错误以及如何消除错误。
Can anyone please explain why the error is and how to eliminate it .



++将对象的值增加1.(a + b)不是对象。要

消除错误,删除++:


#include< stdio.h>


int main(无效)

{

int a = 1;

int b = 2;

int c = 0;


c = a + b;

printf("%d",c);


返回0;

}


-

Richard Heathfield

Usenet是一个奇怪的放置" - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:正常服务将尽快恢复。请不要

调整您的电子邮件客户端。

++ increases the value of an object by 1. (a+b) is not an object. To
eliminate the error, remove the ++:

#include<stdio.h>

int main(void)
{
int a = 1;
int b = 2;
int c = 0;

c = a + b;
printf("%d", c);

return 0;
}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.


raghu写道:
raghu wrote:

#include< stdio.h>

int main(无效)

{

int a = 1;

int b = 2;

int c = 0;

c =(a + b)++;
#include<stdio.h>
int main(void)
{
int a=1;
int b=2;
int c=0;
c=(a+b)++;



空白区域并不昂贵,使代码更容易阅读。


(a + b)是一个表达式,而不是可修改的价值。为什么不c = a + b + 1?


-

Ian Collins。

White space isn''t expensive and makes code easier to read.

(a+b) is an expression, not a modifiable value. Why not c = a+b+1?

--
Ian Collins.


Ian Collins说:
Ian Collins said:

raghu写道:
raghu wrote:

> #include< stdio.h>
int main(void)
{a / 1;
int b = 2;
int c = 0;
c =(a + b) ++;
>#include<stdio.h>
int main(void)
{
int a=1;
int b=2;
int c=0;
c=(a+b)++;



空白区域并不昂贵,使代码更容易阅读。


(a + b)是一个表达式,而不是可修改的价值。为什么不c = a + b + 1?

White space isn''t expensive and makes code easier to read.

(a+b) is an expression, not a modifiable value. Why not c = a+b+1?



为什么+1?

-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:正常服务将尽快恢复。请不要

调整您的电子邮件客户端。

Why the +1?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.


这篇关于左值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆