strcat

Overview :

The "strcat" is used for concatenation of two strings.

Syntax :
char * strcat(char *dest,const char * src);
Description :

The "strcat" function accepts 2 arguments

  • char *dest -> Pointer to string array to hold the concatenated string. It also holds the first string after which the src is added.


  • char *src -> The string to be appended after the first string.


  • The strcat() function appends src at the end of dest and returns dest.
    i.e;

    dest="sun"
    src="rise"


    after concatenation
    dest="sunrise"

  • The terminating NULL character in the dest string is overwritten and src is added after the dest string.The resulting string in dest is NULL terminated. The dest string must have enough space to hold the concatenated string along with the terminating NULL character.



The 'strcat' function returns pointer to the resulting string dest..
Example :
#include<iostream>
#include<string.h>
using namespace std;

int main()

{
    char str1[23],str2[23];
     cout<<"enter string 1 ";
     cin>>str1;
     cout<<"enter string 2 ";
     cin>>str2;

     strcat(str1,str2); 
     cout<<str1;
    return 0;
}

Comments

comments powered by Disqus