0

My code is as follows:

#include <stdio.h>
int main(int argc, char *argv[])
{
    int i=8;
    printf("%d,%d,%d,%d\n",i--, --i, i++, i++);
    return 0;
}

the output in my machine is

9,8,8,8

I know printf executes args from right to left, but the output is seems unexpected, what's wrong here?

Charles0429
  • 1,406
  • 5
  • 15
  • 31
  • 2
    What's wrong here? Your expectations. This is undefined behavior. Please read the comp.lang.c FAQ (http://c-faq.com/expr/index.html) – Jens Feb 10 '14 at 07:50
  • Check: http://stackoverflow.com/questions/14695681/c-c-post-increment-decrement-and-function-call – Fernando Feb 10 '14 at 07:50
  • 3
    This is a duplicate of a lot of other questions. – Jonathan Leffler Feb 10 '14 at 07:50
  • http://codepad.org/BjzfKbBP, http://codepad.org/4PhPRGcb – Abhineet Feb 10 '14 at 07:55
  • "I know printf executes args from right to left". It doesn't, you can't know or assume which order it evaluates them, it is unspecified behavior. It may even evaluate them in different order from call to call. – Lundin Feb 10 '14 at 08:01

0 Answers0