C strcat()

The strcat() function concatenates a copy of str2 to str1 and terminates str1 with a null. The null terminator originally ending str1 is overwritten by the first character of str2. The string str2 is untouched by the operation. If the arrays overlap, the behaviour of strcat() is undefined.

The strcat() function returns str1.

Remember, no bounds checking takes place, so it is the programmer's responsibility to ensure that str1 is large enough to hold both its original contents and those of str2.

strcat() Syntax

Following is the syntax of the strcat() function :

char *strcat(char *str1, const char *str2);

strcat() Example

Following program appends the first string read from stdin to the second. For example, assuming the user enters hello and there, the program prints therehello.

void main()
	char s1[80], s2[80];
	strcat(s2, s1);

C Online Test

« Previous Chapter Next Function »

Like/Share Us on Facebook 😋