Practice mode C Language

Which condition must hold for strcat(dest, src) to work correctly?

Correct answer A. dest must hold a null-terminated string and have room for both strings plus one null byte

Explanation

strcat finds the null terminator of dest and copies src, including its null, from that point. So dest must already be a valid string and its array must be large enough for strlen(dest) + strlen(src) + 1 bytes. strcat does no bounds checking, and overflowing dest is undefined behaviour, a classic buffer overflow. The two strings must also not overlap.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.