++恶魔 [英] ++ devils

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

问题描述

大家好,


我的怀疑是如此原始,我要求大家原谅我

事先......

这里是代码片段:


int main()

{

int x = 5;

x = x ++ + ++ x;

printf("%d",x);

返回0;

}


我知道printf会打印一些x的值,没有人可以

准确预测所有时间对于所有编译器....但是,为什么我要求

这是因为这类问题不断出现在很多

问题论文中....

帮我建议解决这个问题的方法..


提前致谢!

Hello all,

My doubt is going to be so primitive that i ask you all to forgive me
beforehand....

Here''s the code snippet:

int main()
{
int x=5;
x=x++ + ++x;
printf("%d",x);
return 0;
}

I know that the printf is going to print some value of x which none can
predict accurately for all times for all compilers....However,why i ask
this is because such type of questions keep appearing in a lot of
Question Papers....

Help me suggest a way to tackle this..

Thanks in advance!

推荐答案

以及我知道你应该像这样阅读这个等式

x = 5

= x ++ + ++ x

= 5 + 6

= 11

i在某些Windows平台c和c ++中试用它并发现没有变化。

希望它有用

as well as i know you should read this equation like this
x=5
=x++ + ++x
= 5 + 6
=11

i have try it in some windows platform c and c++ and found no change.
hope it will be useful


muttaa写道:
大家好,

我的怀疑是如此原始,我要求大家事先原谅我
....

这里是代码片段:

int main ()
{x / 5;
x = x ++ + ++ x;
printf("%d",x);
返回0;
}

我知道printf会打印一些x值,没有人可以为所有编译器准确预测....但是,为什么我要问
这是因为这类问题不断出现在很多问题论文中....
Hello all,

My doubt is going to be so primitive that i ask you all to forgive me
beforehand....

Here''s the code snippet:

int main()
{
int x=5;
x=x++ + ++x;
printf("%d",x);
return 0;
}

I know that the printf is going to print some value of x which none can
predict accurately for all times for all compilers....However,why i ask
this is because such type of questions keep appearing in a lot of
Question Papers....




行为未定义,x可以现在是任何价值。我建议你

在< http://c-faq.com/expr/index.html>上阅读我们的常见问题解答,从问题开始

3.2。


Robert Gamble



The behavior is undefined, x can now be any value. I would suggest you
read our FAQ at <http://c-faq.com/expr/index.html>, start with question
3.2.

Robert Gamble


在发布后续内容时请引用相关背景,如果你已经

在发布之前潜伏一点(你应该已经完成​​了b
)然后你会知道这一点。由于您使用的是Google网上论坛,

请阅读< http://cfaj.freeshell.org/google/>再次发布之前。


ash写道:
Please quote relevant context when posting followups, if you had been
lurking for a little which before you posted (which you should have
done) then you would know this. Since you are using Google Groups,
please read <http://cfaj.freeshell.org/google/> before posting again.

ash wrote:
以及我知道你应该读这样的等式
x = 5
= x ++ + ++ x
= 5 + 6
= 11

我在一些Windows平台c和c ++中尝试过,发现没有变化。
希望它将是有用的
as well as i know you should read this equation like this
x=5
=x++ + ++x
= 5 + 6
=11

i have try it in some windows platform c and c++ and found no change.
hope it will be useful




错了。仅仅因为它在你的编译器上有一种方式并不意味着蹲下,这种语言并不是由你的编译器定义的。正如我在

响应中所说,结果是未定义的,x可以是包含11的任何内容。

在序列点之间多次修改对象的值

未定义。我建议你遵循我给出的关于常见问题的OP

的相同建议。


Robert Gamble



Wrong. Just because it works one way on your compiler doesn''t mean
squat, the language isn''t defined by your compiler. As I said in my
response, the result is undefined, x can be anything including 11.
Modifying the value of an object more than once between sequence points
is undefined. I suggest you follow the same advice I gave the OP
regarding the FAQ.

Robert Gamble


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

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