ProgrammingHard
char buf[3]; int n = snprintf(buf, 3, "%s", "hello"); printf("%d", n); What is printed?
- A. 2
- B. 3
- C. 6
- D. 5
Correct answer: D. 5
snprintf returns the length the full output would have had, 5, even though only 'he' fits in the 3-byte buffer.
More C Programming questions
- char p = "abc"; printf("%d", (p + 3)); What is printed?
- char s[] = "A1b2"; int d = 0; for (int i = 0; s[i]; i++) if (s[i] >= '0' && s[i] <= '9') d++; printf("%d", d); What is printed?
- char buf[10]; int n = sprintf(buf, "%5.2f", 3.14159); printf("%d", n); What is printed?
- char buf[10]; strncpy(buf, "abc", 10); int zeros = 0; for (int i = 0; i < 10; i++) if (buf[i] == 0) zeros++; printf("%d", zeros); What is…
- printf("%zu", sizeof("a" "bc")); What is printed?
- char c = 'a' + 25; printf("%c", c); What is printed on an ASCII system?