C strcat() method

This function concatenates (appends) one string to the end of another string.

Syntax:


strcat(str1, str2); 

Parameters:

  • str1 is a first string
  • str2 is a second string

Return Value:

  • It returns add of first string to second string.

Note: Make sure the str1 string has enough space to hold both the original string and the appended string.

Example:


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

int main() {
    char str1[10] = "My";
    char str2[] = " World";
    
    strcat(str1, str2);
    printf("Concatenated string: %s\n", str1);  // Output: My World
    
    return 0;
}

Output:

Concatenated string: My World