Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of printf ("%d", 5 > 3 + 2) ?

  • A.0
  • B.1
  • C.False
  • D.None of these

Answer: A

The output is 0.

Arithmetic operators have higher precedence than relational ones, so 3 + 2 is worked out first, giving 5 > 5. That comparison is false, and in C a relational expression evaluates to the int 0 when false and 1 when true. printf with %d prints that integer: 0.

1 is the trap of reading 5 > 3 on its own and ignoring the + 2. printf prints the integer value of the expression, never the word 'False', and since the output is well defined, 'None of these' does not apply.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.