0
#include<studio.h> 

int main ()
{
    int i = 1 ; 

    printf("%d %d %d",i,++i,i++);

    return 0;
}

I thought I would get the answer of the code written above is 1 2 2 . But my compiler showing me the answer 3 3 1 .. Why ?

Filburt
  • 16,951
  • 12
  • 63
  • 111
  • I t is *undefiend behaviour* as linked, but what is happening on *your* computer is (a) `i` value `1` is pushed on the stack and then incremented which is the `i++`. (b) `i` is incremented and then `3` is pushed on the stack which is `++i`. (c) `3` is pushed on the stack which is `i`. But the code does not output `3 3 1` on *my* computer, it outputs `42`. – Weather Vane Jun 24 '21 at 17:23

0 Answers0