邮政和用C pre增量 [英] Post and Pre Increment in C
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/949433/could-anyone-explain-these-undefined-behaviors-i-i-i-i-i-etc\">Could谁能解释这些不确定的行为,(I = I + + + + I,I = I + +,等...)
有一个code以下以下我和马云在理解逻辑为code面临的一个十分严重的问题。
There is a code following below and i ma facing a very serious problem in understanding the logic for the code.
#include <stdio.h>
#include <stdlib.h>
int main(void )
{
int i = 1 ;
printf("\n%d %d %d %d\n",++i,i++,i++,++i) ;
return 0 ;
}
我使用的Mandriva命名的Linux发行版下的gcc编译器。在上述提到的我已经使用pre和后增量与在printf语句的变量。
那我应该得到的输出是2 2 3 5,但我得到一个不同的结果。
请帮我在这code。
I am using gcc compiler under the linux distro named Mandriva. In the above mentioned i have used pre and post increment with a variable in the printf statement. The output that i am supposed to get is 2 2 3 5, but i am getting a different output. Please help me in this code.
我感觉在这个code多的困难。
I am feeling much difficult in this code.
推荐答案
这是未定义的行为。还有的 I
增量之间没有顺序点。
It's undefined behavior. There's no sequence points between the increments of i
.
所有的结果都是一个正确的结果(包括你的硬盘格式化)。
Any result is a correct result (including your hard drive being formatted).
这篇关于邮政和用C pre增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!