Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

strcat — append a string

strcat from <string.h> appends a source string to a destination string. It requires a sufficiently large buffer and does not check its capacity.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <string.h>
char *strcat(char * restrict s1, const char * restrict s2);

strcat(s1, s2) replaces the terminating \0 in s1 with a copy of s2, including its \0. It returns s1, not a pointer to the end of the result.

Both arguments must point to valid null-terminated strings; the destination buffer must be writable and hold at least strlen(s1) + strlen(s2) + 1 bytes. Overlapping objects involved in the copy cause undefined behavior.

The function accepts no buffer capacity and provides no overflow protection. An undersized buffer causes undefined behavior, not safe truncation. Repeated appends can be inefficient: each call searches for the destination string's end again.

Examples

#include <stdio.h>
#include <string.h>

int main(void)
{
    char text[12] = "Hello";
    const char suffix[] = ", C!";

    strcat(text, suffix);
    puts(text);
    return 0;
}

Result

Hello, C!

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources