order of evaluation of function parameters

What will be printed as the result of the operation below:

x=5; 
printf("%d,%d,%d\n",x,x<<2,x>>2); 

Answer: 5,20,1

I thought order is undefined yet I found above as interview question on many sites.


From the C++ standard:

The order of evaluation of arguments is unspecified. All side effects of argument expression evaluations take effect before the function is entered. The order of evaluation of the postfix expression and the argument expression list is unspecified.

However, your example would only have undefined behavior if the arguments were x>>=2 and x<<=2, such that x were being modified.


Bit shift operators don't modify the value of the variable... so order doesn't matter.