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

Discussion

printf ( "%d" , printf ( "tim" ) ):

  • A.results in a syntax error
  • B.outputs tim3
  • C.outputs garbage
  • D.prints tim and terminates abruptly

Answer: B

Correct answer: outputs tim3

The inner printf is evaluated first as the argument to the outer one. It writes tim and returns the number of characters written, which is 3. The outer printf then prints that return value.

So the output is tim followed by 3. The point of the exercise is that printf returns a value at all - the character count - which is easy to forget because it is almost always discarded.

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

Post your comment

Please log in or register to post a comment.