Q-23: Write a C/C++ program to concatenate two given strings.
    

Using - C


#include<stdio.h> void main() { char str1[1024], str2[1024]; int i=0, j, length=0; printf("Enter String-1: "); gets(str1); printf("Enter String-2: "); gets(str2); while(str1[i] != '\0') { length++; i++; } for (j = 0; str2[j] != '\0'; ++j, ++length) { str1[length] = str2[j]; } str1[length] = '\0'; printf("After Concatenation: %s",str1); }

OUTPUT

Enter String-1:  Hello
Enter String-2:  World
After Concatenation:  HelloWorld
        

Using - C++


#include<iostream> using namespace std; int main() { string str1, str2, concat_result; cout<< "Enter String-1: "; getline(cin,str1); cout<< "Enter String-2: "; getline(cin,str2); concat_result = str1 + str2; cout<< "After Concatenation: "<< concat_result; return 0; }

OUTPUT

Enter String-1:  Anuj
Enter String-2:  Das
After Concatenation:  Anuj Das