ProgrammingModerate

char d[8] = "ab"; strncat(d, "cdefgh", 3); printf("%zu", strlen(d)); What is printed?

  1. A. 3
  2. B. 4
  3. C. 6
  4. D. 5

Correct answer: D. 5

strncat appends at most 3 characters and then always writes a terminator, so d becomes 'abcde'. Its length is 5 and the write stays inside the 8 bytes.

More C Programming questions

Exams that ask this topic