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?

  1. A. 4 wxyz
  2. B. 4 wxy
  3. C. 3 wxy
  4. 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

Exams that ask this topic