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

Discussion

What will be the output of the following statement ?

int a = 10; printf("%d &i", a,10);

  • A.error
  • B.10
  • C.10 10
  • D.None of the above

Answer: D

The output is 10 &i, so the answer is None of the above.

The format string "%d &i" contains only one conversion specifier, %d, which prints the value of a, 10. The rest, a space followed by the characters &i, is ordinary text and is printed as it stands. The extra argument 10 has no specifier to use it and is ignored; C allows surplus arguments to printf.

'10 10' would be the output of "%d %i"; with & instead of % the second number is never printed. The statement compiles, so it is not an error.

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

Post your comment

Please log in or register to post a comment.