差异I = I + + + +的C输出;且i = ++ I + C ++; [英] Difference in output of i=i++ + ++c; and i=++i + c++;

查看:138
本文介绍了差异I = I + + + +的C输出;且i = ++ I + C ++;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是编译器特定的,但是当我试图运行两位前pressions DEVC ++

I don't know if this is compiler specific but when I tried running the two expressions in DevC++

I = C = B = 0; I = I + + + +ç 2 ,而 I = + I + C ++ 1

不过,
     B = I + + + +ç
     B = + I + + +ç产生的结果 1 这两个前pressions。

But b=i++ + ++c and b=++i + ++c produces the result 1 for both expressions.

我不知道,在一个未定义的值在相同的前pression结果递增一个变量两次根据 C 标准规范,但我很好奇如何编译器生成这些输出。可能有人请解释如何,为什么?

I do know that incrementing a variable twice in the same expression results in an undefined value according to the C standard specification but I'm curious how the compiler produces these output. Could someone please explain how and why?

推荐答案

我++ ++我完全不同,我++ 是后递增,这意味着评估 I 在EX pression然后递增一次的评估。 ++我表示则增量评估前pression。
我在你的例子中看到您设置 I = ++ I / I ++ ,这是因为在评论中提及未定义的行为。

i++ and ++i are completely different, i++ is post increment which means evaluate i in the expression and then increment once its evaluated. ++i means increment then evaluate the expression. I see in your example you set i = ++i/i++, this is undefined behavior as mentioned in a comment.

这篇关于差异I = I + + + +的C输出;且i = ++ I + C ++;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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