Open In App

strcat() in C

C strcat() function appends the string pointed to by src to the end of the string pointed to by dest. It will append a copy of the source string in the destination string. plus a terminating Null character. The initial character of the string(src) overwrites the Null-character present at the end of the string(dest).

It is a predefined string handling function under string library <string.h> in c and <cstring> in C++.



Syntax:

char *strcat(char *dest, const char *src);

Parameters: The method accepts the following parameters:



Return value:

 

Examples:

Input: src = "ForGeeks"
       dest = "Geeks"
Output: "GeeksForGeeks"

Input: src = "World"
       dest = "Hello "
Output: "Hello World"

Below is the C/C++ program to implement the above approach:




// C program to implement
// the above approach
#include <stdio.h>
#include <string.h>
  
// Driver code
int main()
{
    // Define a temporary variable
    char example[100];
  
    // Copy the first string into
    // the variable
    strcpy(example, "Geeks");
  
    // Concatenate this string
    // to the end of the first one
    strcat(example, "ForGeeks");
  
    // Display the concatenated strings
    printf("%s\n", example);
  
    return 0;
}

Output
GeeksForGeeks

The behavior of strcat() is undefined if:

Article Tags :