C Program to Concatenate Two Strings Using String Function strcat()

In this program, the user is ask to enter the two strings, then the two strings are combined using strcat() string function. The strcat() function concatenates (joins) two strings. The function definition of strcat() is: char *strcat(char *destination, const char *source) It is defined in the string. h header file. For example, s1 = "Hello," s2 = "How are you?" Then after string concatenation (means s1 + s2) you will get "Hello, How are you?".

Source Code

int main()
    char str1[40], str2[20];
    printf("Enter first strings:");
    scanf("%s", str1);
    printf("Enter second strings:");
    scanf("%s", str2);
    strcat(str1, str2);
    printf("\nConcatenated string is\n %s", str1);
    return 0;
Enter first strings:Hello
Enter second strings:Wordl!!

Concatenated string is

"Coding Hub - Learn to code" app now available on Google Play Store