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
using namespace std;

int main()
    char str1[40], str2[20];
    cout<<"Enter first strings:";
    cin>> str1;
    cout<<"Enter second strings:";
    cin>> str2;
    strcat(str1, str2);
    cout<<"\nConcatenated string is\n "<< str1;
    return 0;
Enter first strings:Hello
Enter second strings:Wordl!!

Concatenated string is