C Program to Concatenate Two Strings Using a Pointer Last Updated : 28 Nov, 2024 Comments Improve Suggest changes Like Article Like Report Concatenating two strings means appending one string at the end of another string. While the standard library provides strcat() for concatenation, this article will demonstrate how to concatenate two strings using pointers.To concatenate two strings using pointers, traverse the first string to its null terminator and then start appending characters from the second string until its null terminator is reached. C #include <stdio.h> void concat(char *s1, char *s2) { // Move pointer to the end of first string while (*s1) s1++; // Append each character of the second string while (*s2) { *s1 = *s2; s1++; s2++; } // Null-terminate the concatenated string *s1 = '\0'; } int main() { char s1[100] = "Hello, "; char s2[] = "World!"; // Call the concatenation function concat(s1, s2); printf("%s\n", s1); return 0; } OutputHello Geeks Explanation: The pointer s1 is incremented to move it to the end of the first string. Then characters from s2 are copied to the position pointed by s1. The pointer is incremented for both strings after each character is copied. After all characters from s2 are appended, a null terminator ('\0') is added at the end to complete the concatenated string. Create Quiz Comment R rajpootveerendrasingh36 Follow 0 Improve R rajpootveerendrasingh36 Follow 0 Improve Article Tags : C Programs C Language C-Pointers C-String C Examples +1 More Explore C BasicsC Language Introduction6 min readIdentifiers in C3 min readKeywords in C2 min readVariables in C4 min readData Types in C3 min readOperators in C8 min readDecision Making in C (if , if..else, Nested if, if-else-if )7 min readLoops in C6 min readFunctions in C5 min readArrays & StringsArrays in C4 min readStrings in C5 min readPointers and StructuresPointers in C7 min readFunction Pointer in C5 min readUnions in C3 min readEnumeration (or enum) in C5 min readStructure Member Alignment, Padding and Data Packing8 min readMemory ManagementMemory Layout of C Programs5 min readDynamic Memory Allocation in C7 min readWhat is Memory Leak? How can we avoid?2 min readFile & Error HandlingFile Handling in C11 min readRead/Write Structure From/to a File in C3 min readError Handling in C8 min readUsing goto for Exception Handling in C4 min readError Handling During File Operations in C5 min readAdvanced ConceptsVariadic Functions in C5 min readSignals in C language5 min readSocket Programming in C8 min read_Generics Keyword in C3 min readMultithreading in C9 min read Like