Question.7
A developer uses strncpy for a safe copy:
char buf[8]; strncpy(buf, "FIRMWARE_V2", sizeof(buf)); printf("%s", buf);
The source string (11 chars + \0) is longer than the buffer (8). What happens?
Select Answer
buf contains "FIRMWARE" with a null terminator — safe and correct
buf
FIRMWARE
buf contains "FIRMWARE" without a null terminator — printf overreads memory
printf
Compilation error — strncpy detects the size mismatch
strncpy
buf is truncated to "FIRMWAR" with a null terminator at buf[7]
FIRMWAR
buf[7]