ProgrammingVery hard
printf("[%5s|%-5s]", "ab", "cd"); What is printed?
- A. [ cd|ab ]
- B. [ ba|cd ]
- C. [ ab|cd ]
- D. [ ab|dc ]
Correct answer: C. [ ab|cd ]
A plain width right-aligns and the minus flag left-aligns, so ab is padded on the left and cd on the right.
More C Programming questions
- 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?
- char cnt[26] = {0}; cnt['c' - 'a']++; printf("%d", (int)('c' - 'a')); What is printed?