发布和预增量 [英] post and pre increment

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

问题描述

有什么区别

1. y = ++ x ++;

2. y =(++ x)++;

3. y = ++(x ++);

what is difference between
1. y=++x++;
2. y=(++x)++;
3. y=++(x++);

推荐答案

@jyots


您是否尝试编译示例? ?如果是这样,你会注意到它们都没有编译。 A ++运算符(前置和后置)将左值作为其操作数,其结果为右值,因此您不能连续应用其中的两个。


亲切的问候,


Jos
@jyots
Have you tried to compile your examples? If so, you would''ve noticed that none of them compile. A ++ operator (pre- and post) takes an lvalue as its operand and its result is an rvalue so you can''t apply two of them in a row.

kind regards,

Jos


y =(++ x)++;


这句话是givin没有问题...但其余的都是givin错误..
y=(++x)++;

this statement is givin no problem... but rest of them are givin error..


@jyots


表达式也不应该编译;如果您的编译器接受它,请抛弃您的编译器并安装一个像样的编译器这就是标准所说的:

@jyots
That expression shouldn''t compile either; if your compiler accepts it throw your compiler away and install a decent one. This is what the Standard has to say about it:


[#2]除非它是sizeof运算符的操作数,否则

the unary&运算符,++运算符, - 运算符,或者

左运算符。运算符或赋值

运算符,没有数组类型的左值是

转换为存储在指定对象中的值(和

不再是左值)
。如果左值具有合格类型,则该值具有

左值类型的非限定版本;否则,该值具有左值的类型。如果

左值有一个不完整的类型,并且没有数组
[#2] Except when it is the operand of the sizeof operator,
the unary & operator, the ++ operator, the -- operator, or
the left operand of the . operator or an assignment
operator, an lvalue that does not have array type is
converted to the value stored in the designated object (and
is no longer an lvalue)
. If the lvalue has qualified type,
the value has the unqualified version of the type of the
lvalue; otherwise, the value has the type of the lvalue. If
the lvalue has an incomplete type and does not have array



亲切的问候,


Jos

kind regards,

Jos


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

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