增量如何发生在printf语句用C [英] How does incrementation takes place in printf statement in C
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/12529682/unexplained-behavior-of-printf-i-i-and-variants\">Unexplained行为上的printf(...,我,我++);和变种
块引用>我打印上面的线。但我得到的结果作为65.How没有我增加和打印尽管我是在第二次??
递增INT I = 5;
的printf(%D,我,我++);
解决方案您
的printf
调用产生的未定义行为的。它是非法修改I
(在我++
),并在同一时间执行<$ C $的一个独立的读C> I 没有插入顺序点。不同的评价令不事在这里。所有试图解释这个code的基础上,或会发生什么的评价令的行为之前和之后发生什么事是绝对不正确。行为简直是不确定的。故事结局。
至于C语言本身而言,这code可以打印
杀死所有的人!
,程序崩溃,格式化你的硬盘或者干脆拒绝编译。Possible Duplicate:
Unexplained behavior of ‘printf(…, i, ++i);’ and variantsI printed the above line. But I got the result as 65.How does I increment and print despite the fact that I is incremented at the second time??
int i=5; printf("%d%d",i,i++);
解决方案Your
printf
call produces undefined behavior. It is illegal to modifyi
(ini++
) and at the same time perform an independent read ofi
without an intervening sequence point.Various "orders of evaluation" do not matter here. All attempts to explain the behavior of this code based on the "orders of evaluation" or what happens "before" and what happens "after" are absolutely incorrect. The behavior is simply undefined. End of story.
As far as the C language itself is concerned, this code can print
"Kill all humans!"
, crash the program, format your hard drive or simply refuse to compile.这篇关于增量如何发生在printf语句用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!