ProgrammingModerate

char d[6] = "abc"; /* we want strncat(d, "defgh", 5) with no overflow */ What is the smallest size d needs?

  1. A. 6
  2. B. 9
  3. C. 8
  4. D. 10

Correct answer: B. 9

strncat may append 5 characters and then needs a terminator, so 3 + 5 + 1 = 9 bytes are required. The 6-byte array overflows.

More C Programming questions

Exams that ask this topic