C Program to Concatenate Two Strings Using Pointers
Character array is called string. The last character is always null in a string represented by \0. The indexing always start from 0 in any array.
In the following program pointers are used to copy the value of bb string to aa string
- //C program to concatenate strings using pointers
-
- #include <stdio.h>
- int main()
- {
- char aa[100], bb[100]; //array declaration
- printf("\nThe string after concatenation is: %s ", aa);
- printf("\nEnter the first string: ");
- gets(aa); //using gets allows us to take string inputs along with spaces
- printf("\nEnter the second string to be concatenated: ");
- gets(bb);
-
- char *a = aa;
- char *b = bb;
-
- while(*a)
- {
- a++;
- }
- while(*b)
- {
- *a = *b;
- b++;
- a++;
- }
- *a = '\0'; // string must end with '\0'
- printf("\n\n\nThe string after concatenation is: %s ", aa);
- return 0;
- }
Output

Solution not working or have any suggestions? Please send an email to [email protected]
Download Android App