C strcat() function with example


The strcat() library function in C Language concatenates two strings. This function appends string to the original destination string and returns the pointer to the destination string.

Basic Syntax

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

And the parameters are:

Parameter Description
dest This parameter specifies the pointer to destination array to which string to be appended. It should have enough space to contain the resulting string.
src This specifies the string to be appended

Return Value

This function returns the pointer to the destination string dest.

Example

1. Following is the example for strcat() function in C.

// C program for illustration of function strcat() function in C Language
#include 
#include 

int main () {
   char src[] = "CrazyGeeks.ORG";
   char dest[] = "Welcome to ";

   strcat(dest, src);

   printf("Final destination string: %s", dest);
   
   return(0);
}

The output should be:

Final destination string: Welcome to CrazyGeeks.ORG

2. Following is the example for strcat() function in C.

// C program for illustration of function strcat() function in C Language
#include 
#include 

int main () {
   char src[] = "Programming ";
   char dest[] = "Java";

   strcat(dest, src);

   printf("Final destination string: %s", dest);
   
   return(0);
}

The output should be:

Final destination string: Java Programming