ProgrammingVery hard
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?
- A. 4 wxyz
- B. 4 wxy
- C. 3 wxy
- D. 3 wxyz
Correct answer: B. 4 wxy
snprintf would need 4 characters and returns 4. Only the first three fit in the buffer with the terminator, so buf holds 'wxy'.
More C Programming questions
- 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?
- printf("%s", (char[]){'h', 'i', '0'}); What is printed?
- char a = "ab", b = "ab"; printf("%d", strcmp(a, b) == 0); What is printed?
- char buf[8] = "12345"; buf[strlen(buf) - 1] = '0'; printf("%s", buf); What is printed?