what should be the output of this code?
int n=1
printf("%d %d %d\n",n,n++,n++);
shouldn’t it 1 2 3 ?
but my pc gives output 3 2 1 .
what should be the output of this code?
int n=1
printf("%d %d %d\n",n,n++,n++);
shouldn’t it 1 2 3 ?
but my pc gives output 3 2 1 .
printf puts its argument in a stack before priniting it and it evaluates from right to left.So first it ll evaluate last n++.But since it is post increment ,first it ll put value of n(=1) in the stack nd then increment it.
Now n=2,so 2 is inserted into the stack and n is incremented to 3.
Finally value of n is pushed to stack
So stack contains 3 2 1.
Thus 3 2 1 is printed.
(But I think behaviour depends on compiler)
Dude visit this website and you will completely understand