parameter passing in function

int main()
int i=5;
printf("%d %d %d %d %d",i++,i–,++i,–i,i);
return 0;

It’s giving a output 4 5 5 5 5,but it should be 4 5 5 4 5.Why is this happening?

1 Like

I think there is some problem with ur machine, in my machine m getting output 4 5 5 4 5 only.

I ran your code on Ideone and got the output as 4 5 5 5 5. Here is the link .Since Codechef and Ideone use the same judge , you will get same result here also. Codeblocks is also giving output as 4 5 5 5 5.

I googled this out and found 2 useful links : link 1 and and link 2. Infact link 2 has exactly the same question as yours.

**From the 2 links you can conclude that the order in which the parameters to a function in not defined by any standard, and is determined by the calling convention used by the compiler.**Hence you will get different output for this question depending on the Compiler used.

If anyone asks any such question to you in a test or interview you can simply write “Cannot be predicted” or “Compiler dependent”


Please read this:

which compiler did you use?

thanks for your help…