C Program to Compare Two Strings Using Pointers Last Updated : 28 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 while comparing each character at corresponding position. If both strings are completely traversed without finding any mismatch, then they are considered equal. Otherwise, they are unequal. C #include <stdio.h> int strCmp(char *s1, char *s2) { // Traverse both strings until a mismatch // is found or one of the string ends while (*s1 && (*s1 == *s2)) { // Move to the next character in str1 s1++; s2++; } // If both are equal, this will return 0 return (*s1 - *s2); } int main() { char s1[] = "GeeksforGeeks"; char s2[] = "Geeks"; int res = strCmp(s1, s2); if (res < 0) { printf("\"%s\" is lexicographically smaller than \"%s\".\n", s1, s2); } else if (res > 0) { printf("\"%s\" is lexicographically greater than \"%s\".\n", s1, s2); } else { printf("\"%s\" is lexicographically equal to \"%s\".\n", s1, s2); } return 0; } Output"GeeksforGeeks" is lexicographically greater than "Geeks". Explanation: This method uses pointer dereferencing to compare characters in the strings using equality operator. The pointer is incremented to iterate through the strings until the end of one string is reached. Comment More infoAdvertise with us Next Article C Program to Print the Length of a String using Pointers J jeshwanthb4mwy Follow Improve Article Tags : C Programs C Language C-Pointers C-String C Examples +1 More Similar Reads C Program to Concatenate Two Strings Using a Pointer 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 n 1 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 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 Lexicographically In C, lexicographic comparison refers to comparing each character of one string to the character of other string at same position based on their alphabetical order, just like how words are arranged in a dictionary. In this article, we will learn how to compare two strings lexicographically using the 3 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 check if two given strings are isomorphic to each other Given two strings str1 and str2, the task is to check if the two given strings are isomorphic to each other or not. Two strings are said to be isomorphic if there is a one to one mapping possible for every character of str1 to every character of str2 and all occurrences of every character in str1 ma 2 min read Like