Register
 

Free CSC Scholarship support for 2018-19

Engineering, Computer, Scholarship and SEO Support Forum




Author Topic: If n has the value 3, then the output of the statement printf{"%d %d", n++, ++n}  (Read 1311 times)

Offline mechanic

  • Engineer
  • Hero Engineer
  • *****
  • Posts: 2985
    • View Profile
    • Engineering Forum
Advertisement
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.

Engineering, Computer, Scholarship and SEO Support Forum