c - Need explanation for the output -


possible duplicate:
could explain these undefined behaviors (i = i++ + ++i , = i++, etc…)

#include<stdio.h> void main() { int a=5; printf("%d\t%d\t%d\n",a,a++,++a); } 

output of above program showing 7 6 7 in gcc version 4.4.3 (ubuntu 4.4.3-4ubuntu5). why showing instead of 7 6 6 ?

your program can show likes , output correct.

the behaviour undefined; allowed happen.

what's undefined?

  • incrementing a twice in argument list printf().

the behaviour of void main() @ best implementation-defined. return type of main() should int.


iso/iec 9899:2011 (c 2011) standard

§ 6.5 expressions

¶2 if side effect on scalar object unsequenced relative either different side effect on same scalar object or value computation using value of same scalar object, behavior undefined. if there multiple allowable orderings of subexpressions of expression, behavior undefined if such unsequenced side effect occurs in of orderings.84)

84) paragraph renders undefined statement expressions such as

    = ++i + 1;     a[i++] = i; 

while allowing

    = + 1;     a[i] = i; 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -