If n has the value 3, then the output of the statement printf{"%d %d", n++, ++n}

  • 0 replies
  • 1541 views
*

Offline mechanic

  • *****
  • 3090
    • View Profile
    • Engineering Forum
Question: If n has the value 3, then the output of the statement printf{"%d %d", n++, ++n};

Options are:


A. is 3 5
B. is 4 5
C. is 4 4
D. is implementation dependent

Correct answer is:

D. is implementation dependent


Explanation:


Most of the compilers give 4  4 as the output. This is because most of the compilers use stacks to evaluate the arguments. If so, the first argument n++ will be pushed before the ++n is pushed. This implies that ++n will be evaluated before n++ is evaluated. However, the order of printing will be in accordance with the order the variables are listed in the printf statement.