意外的结果 [英] unexpected result

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

问题描述



看看这段代码


包含< stdio.h>

int main(void)

{

int i,j = 2;

i = j ++ * ++ j * j ++;

printf(" ;%d%d,i,j);

返回0;

}


acc。对我来说i&的价值观j分别为27,5和这是正确的,因为我在turbo c ++编译器上运行了这个,但如果我在lcc-win32编译器上运行它

我得到32& 5对于i&分别为。

为什么会这样呢

hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so

推荐答案

hi anshu

所有编译器依赖者

in lcc-win32编译器

首先代码从右到左运行

表示i = 4 * 4 * 2

它为我提供32

但在turboc编译器中它从左到右执行代码并取大价值

其中就是3

所以它给它27.

再见

Ankur


ashu写道:
hi anshu
it all compiler depenedent
in lcc-win32 compiler
first the code run on right to left
means i=4*4*2
it give 32 for i
but in turboc compiler it execute code left to right and take big value
among it i.e. 3
so thats y its give 27.
bye
Ankur

ashu wrote:

看看这段代码

包含< stdio.h>
int main(无效)
{
int i,j = 2 ;
i = j ++ * ++ j * j ++;
printf("%d%d",i,j);
返回0;
}

acc。对我来说i&的价值观j分别为27,5和这是正确的,因为我在turbo c ++编译器上运行了这个,但如果我在lcc-win32编译器上运行它

我得到32& 5对于i&分别为。
为什么会这样?
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;
printf("%d %d",i,j);
return 0;
}

acc. to me the values of i & j are 27,5 respectively & rightly so as i
ran this on turbo c++ compiler but if i ran this on lcc-win32 compiler
i got 32 & 5 for i & j respectively.
why this is so






ashu写道:
ashu wrote:
hi
看看这段代码

包含< stdio.h>
int main(void)
{
int i,j = 2;
i = j ++ * ++ j * j ++;
hi
look at this code

include <stdio.h>
int main(void)
{
int i,j=2;
i=j++ * ++j * j++;




未定义的行为:请参阅常见问题解答。


(非正式地说,你以随机顺序更新j三次;

你为什么期望结果有意义?除了它更糟糕

之外。)


-

Chris" sparqling" Dollin

你服务的对象是谁,你信任谁?



Undefined behaviour: see the FAQ.

(Informally speaking, you update j three times in random order;
why do you expect the result to make sense? Except it''s worse
than that.)

--
Chris "sparqling" Dollin
"Who do you serve, and who do you trust?"


嗨极客,

请告诉我哪本书给出了C和C ++动态内存管理的完整

详细信息。

Hi geeks,
Please tell me which book gives the complete
detail of dynamic memory management in C and C++.


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

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