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. Comment More infoAdvertise with us Next Article C Program to Concatenate Two Strings Using a Pointer rajpootveerendrasingh36 Follow Improve Article Tags : C Programs C Language C-Pointers C-String C Examples +1 More Similar Reads C Program to Compare Two Strings Using Pointers In C, two strings are generally compared character by character in lexicographical order (alphabetical order). In this article, we will learn how to compare two strings using pointers.To compare two strings using pointers, increment the pointers to traverse through each character of the strings whil 2 min read C Program to Concatenate Two Strings Without Using strcat String concatenation is the process of appending one string to the end of another. C language provides strcat() library function to concatenate string but in this article, we will learn how to concatenate two strings without using strcat() in C.The most straightforward method to concatenate two stri 3 min read C Program to Print the Length of a String using Pointers C language provides a built-in function strlen() but in this article, we will learn how to find and print the length of the string using pointers in C.The easiest method to find the length of a string using pointers is by calculating difference between the pointers to the first and last character of 2 min read C Program to Compare Two Strings Without Using strcmp() String comparison refers to the process of comparing two strings to check if they are equal or determine their lexicographical order. C provides the strcmp() library function to compare two strings but in this article, we will learn how to compare two strings without using strcmp() function.The most 2 min read Concatenating Two Strings in C Concatenating two strings means appending one string at the end of another string. In this article, we will learn how to concatenate two strings in C.The most straightforward method to concatenate two strings is by using strcat() function. Let's take a look at an example:C#include <stdio.h> #i 2 min read C Program to Find the Length of a String The length of a string is the number of characters in it without including the null character (â\0â). In this article, we will learn how to find the length of a string in C.The easiest way to find the string length is by using strlen() function from the C strings library. Let's take a look at an exa 2 min read C Program to Swap Adjacent Characters of a String In this article, we will learn how to swap adjacent characters of a string in C. To swap all adjacent characters in a string, the string must have an even number of characters. If the number of characters is odd, the last character remains unswapped since it has no adjacent element.The most straight 3 min read C program to reverse the content of the file and print it Given a text file in a directory, the task is to print the file content backward i.e., the last line should get printed first, 2nd last line should be printed second, and so on.Examples: Input: file1.txt has: Welcome to GeeksforGeeks Output: GeeksforGeeks to WelcomeGeeksforGeeks Input: file1.txt has 3 min read C program to append content of one text file to another Pre-requisite: File Handling in C Given the source and destination text files, the task is to append the content from source file to destination file and then display the content of the destination file.Examples: Input: file1.text This is line one in file1 Hello World. file2.text This is line one in 2 min read C Program to Add 2 Binary Strings Given two Binary Strings, we have to return their sum in binary form.Approach: We will start from the last of both strings and add it according to binary addition, if we get any carry we will add it to the next digit.Input: 11 + 11Output: 110C// C Program to Add 2 Binary Strings // and Print their B 8 min read Like