What is order of evaluation of printf function? What is the order of evaluation of function parameters in c programing. Let us see below example and predict the output.



The evaluation order of function parameters in C language is compiler dependent. This is not limited  to printf function only.Why is the order of evaluation for function parameters unspecified in c/c++?
C/C++ compiler takes source code as a input and generates executable to run a program. Most of the Native compiler before making exe it does optimization. The compiler re-order the evaluation of the operands to generate more optimized exe. preventing re-ordering of the evaluation of the operands would prevent the compiler to optimize.

Let us see another example of function parameters

Output: ( compiled with gcc on Linux)


C or C++ standard language does not give any guaranty that the increments will be evaluated in any particular order. It is totally dependent on compiler optimization. So prevent this type programming to prevent side effects of ++ or — operator.

Related Contents to follow