C Introduction
Control Statement
Functions
Array
Pointers
Structure and Union
No Examples found for this topic - CodeHelpPro
Data Files
No Examples found for this topic - CodeHelpPro
Program to Concatenate Strings using Pointer
In this example, We will learn a simple program to Concatenate Strings using Pointer. Before that, You must have knowledge of the following topics.
Algorithm
This is the algorithm of this program
Step 1: Start Step 2: Initialize string variables aa and bb Step 3: Takes string input from user and store in aa and bb Step 4: Declare Pointer variables a and b Step 5: a = aa and b = bb step 6: REPEAT this step until pointer a is NULL Increase a by 1 step 7: REPEAT this step until pointer b is NULL *a = *b Increase b by 1 Increase a by 1 Step 8: *a = \'\\0\' Step 9: Print aa Step 10: End
Flowchart
This is the flowchart of this program

CODE: Concatenate Strings using Pointer
Now, We will see the main code to concatenate two strings using pointers.
#include <stdio.h>
int main()
{
char aa[100], bb[100];
printf("\nEnter string: ");
gets(aa);
printf("\nEnter the string to be concatenated: ");
gets(bb);
char *a = aa;
char *b = bb;
// pointing to the end of the 1st string
while(*a)
{
a++;
}
while(*b)
{
*a = *b;
b++;
a++;
}
*a = '\0';
printf("\nThe string after concatenation is: %s ", aa);
return 0;
}
The output of above program is
Enter string: Hello
Enter the string to be concatenated: World
The string after concatenation is: Hello World
Subscribe
Login
0 Comments
Inline Feedbacks
View all comments