The strcat() function is used for string concatenation in C programming language. It means it joins the two strings together. Its syntax is as follows –
String1 and string2 are character arrays. It concatenates (joins) second string at the end of the first string. It does so by removing the null character at the end of the string1 and placing string2 from there. The string at string2 remains unchanged. For example, consider the following two strings –
Also we must make sure that the size of the string1 to which the string2 is concatenated is large enough to accommodate the final string.
C strcat() function may also append a string constant to a string variable. The following is valid:
It is also permitted nesting of strcat functions in c programming. For example the statement –
is allowed and concatenates all the three strings together. The resultant string is stored in string1.
Sample C strcat( ) program to concatenate two strings –
Enter first string – Study
Enter another string – Street
Concatenated string – Study Street