ProgrammingModerate
printf("[%03d]", 7); What is printed?
- A. [7]
- B. [007]
- C. [0007]
- 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
- printf("[%5s|%-5s]", "ab", "cd"); What is printed?
- printf("%x %o", 255, 8); What is printed?
- char s[5] = "abcd"; printf("%s", s + 2); What is printed?
- char buf[4]; int n = snprintf(buf, sizeof buf, "%c%c%c%c", 'w', 'x', 'y', 'z'); printf("%d %s", n, buf); What is printed?
- char names[] = {"ab", "cde"}; printf("%zu", sizeof names / sizeof names[0]); What is printed?
- for (char c = 'a'; c <= 'e'; c += 2) putchar(c); What is printed?