-5

I wrote the following simple program

#include<stdio.h>
int main()  
{  
    int i;  
    i=1;  
    printf("%d %d %d",i,i++,++i);  
    return 0;  
} 

The above program gave 3 2 3 as output which I am not able to interpret the output. I am using gcc-4.8.1

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
Mayur Rao
  • 11
  • 1

1 Answers1

1

You have undefined behavior here!!

When there are multiple increments to the same variable in the printf() you can't predict the output. The order of execution within the printf() is not defined.

Gopi
  • 19,784
  • 4
  • 24
  • 36