If strncpy(dst, src, n) is called and src has n or more characters, what is true about dst afterwards?
Correct answer D. dst is not null-terminated
Explanation
strncpy copies at most n characters. If src is shorter it pads the rest of dst with null bytes, but if src has n or more characters it copies exactly n and adds no terminator, leaving dst without a null. Passing such a dst to printf or strlen then reads past the array. A safe pattern is to copy n - 1 characters and set dst[n - 1] = '\0' yourself.
Answer checked How we write and check questions
Discussion