Write a program in C++ to concatenate two strings into third
string using pointers

Answer Posted / naman patidar

#include <iostream.h>
#include <string.h>

void main(){
char *str1 = "First String";
char *str2 = "Second String";
int len = strlen(str1)+strlen(str2)+1;
char *result = new char[len];

int i ;
for( i =0 ; i<strlen(str1); i++){
result[i] = str1[i];
}
for(int j=0; j<strlen(str2); j++, i++) {
result[i] = str2[j];
}
result[i] ='\0';
cout<<result;
}

Is This Answer Correct ?    88 Yes 58 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

i wanted to know about questions about c,c++ , which is required for placements.... im a fresher

1920


Why should a c++ programmer be interested in stl?

849


a program using one dimensional array that searches a number if it is found on the list of given input numbers given by the user and locate its exact location in the list.

1607


What does stl mean in slang?

845


What two types of containers does the stl provide?

754


What is stl stack?

869


What is stl in c++ with example?

849


How do I convert a stl file?

771


write a program that will accept a number and print.its equivalent in words the maximum input number is 9999

2709


In what scenario does the Logical file and Physical file being used?

2546


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

2362


Can we use stl in coding interviews?

1552


What is stl language?

858


write a program to convert a decimal number in to its equivalent binary number?

2274


how can u do connectivity in c++ language? plz send me connectivity code in c++ ?

2102