ProgrammingModerate

printf("[%03d]", 7); What is printed?

  1. A. [7]
  2. B. [007]
  3. C. [0007]
  4. D. [700]

Correct answer: B. [007]

%03d sets a minimum width of 3, and the 0 flag pads on the left with zeros instead of spaces, giving 007. [7] ignores the width, [700] pads on the wrong side, and [0007] adds a zero on top of the width.

More C Programming questions

Exams that ask this topic