Q:

Write C program to concatenate two strings using pointer

0

Write C program to concatenate two strings using pointer

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
#define MAX_SIZE 100 // Maximum string size
 
int main()
{
    char str1[MAX_SIZE], str2[MAX_SIZE];
    char * s1 = str1;
    char * s2 = str2;
 
    // Inputting 2 strings from user
    printf("Enter 1st string: ");
    gets(str1);
    printf("Enter 2nd string: ");
    gets(str2);
 
    // Moving till the end of str1
    while(*(++s1));
 
    // Coping str2 to str1
    while(*(s1++) = *(s2++));
 
    printf("Concatenated string: %s", str1);
 
    return 0;
}

Result:

Enter 1st string: Tech

Enter 2nd string: Study

Concatenated string: TechStudy

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now