Concatenate two strings using library function

Q. Write C++ program to concatenate the two strings without using library function.


using namespace std;
void concatString(char[], char[]);

int main()
        char str1[50], str2[30];
        cout<<"\n Enter First String : ";    //Accepting two strings from user
        cout<<"\n Enter Second String : ";
        concatString(str1, str2);
        cout<<"\n Concatenated string is : "<<str1;
        return (0);
void concatString(char str1[], char str2[])  //Function 'concatString' for concatenation of two strings
        int i, j;
        i = strlen(str1);       //Calculating the size of the first string
        for (j = 0; str2[j] != '\0'; i++, j++)
                str1[i] = str2[j];
        str1[i] = '\0';


concat string witout standard function


concat string witout standard function

The above figure shows the flow of concatenation of two strings that define how actually it works without using standard function (strcat()).   

Using 'For' loop, it iterates second string character by character and puts each character to the end of the first string.