C Program to concatenate two Strings using pointer


In this article, I will show you how you can write a C Program to concatenate two Strings using pointer. I will explain the algorithm, concepts and then help you to write C Program to concatenate two Strings using pointer.

1. Program Outline

In this program, we will take two Strings as input from the user. We will then concatenate those Strings using Pointer.
To write a C Program to concatenate two Strings using pointer. Open your favorite code editor and Let’s start writing C Program to concatenate two Strings using pointer.

2. Concepts

To write this C Program to concatenate two Strings using pointer, you need to learn the following concepts of C Programming:

  1. Input
  2. Pointer
  3. Increment/Decrement operator
  4. Output

3. Algorithm

To write this C program, follow this Algorithm:

Step 1: START
Step 2: Input the String
Step 3: Add Pointer
Step 4: Concatenate the String
Step 5: Output concatenated String
Step 6: STOP

4. Program

Here’s the C Program to concatenate two Strings using pointer:

#include <stdio.h>
#define MAX_SIZE 100
 
int main()
{
    char str1[MAX_SIZE], str2[MAX_SIZE];
    char * s1 = str1;
    char * s2 = str2;
 
    // Getting String as Input
    printf("Enter 1st string: ");
    gets(str1);
    printf("Enter 2nd string: ");
    gets(str2);
    while(*(++s1));
    while(*(s1++) = *(s2++));
 
    printf("Concatenated string: %s", str1);
    return 0;
}

5. Output

Here’s the output of the above C Program:

        Welcome to CodeWin.org!!!

Enter the first string: Code 

Enter the second string to be concatenated: Win



The string after concatenation is: CodeWin 

            Learning is Fun with CodeWin.org !

C Program to concatenate two Strings using pointer
Repl.it Compiler

6. Resources

If you want to try this C Program on your own PC or Mobile, you can download these files:

Similar Posts

Leave a Reply

Your email address will not be published.