C++ Program to compare two string using pointers Last Updated : 07 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given two strings, compare the strings using pointers Examples: Input: str1 = geeks, str2 = geeks Output: Both are equal Input: str1 = hello, str2 = hellu Output: Both are not equal As their length are same but characters are different The idea is to dereference given pointers, compare values and advance both of them. C++ // C++ Program to compare two strings using // Pointers #include <iostream> using namespace std; // Method to compare two string // using pointer bool compare(char *str1, char *str2) { while (*str1 == *str2) { if (*str1 == '\0' && *str2 == '\0') return true; str1++; str2++; } return false; } int main() { // Declare and Initialize two strings char str1[] = "geeks"; char str2[] = "geeks"; if (compare(str1, str2) == 1) cout << str1 << " " << str2 << " are Equal"; else cout << str1 << " " << str2 << " are not Equal"; } Outputgeeks geeks are Equal Complexity analysis: Time Complexity: O(min(M, N)), where M and N represents the length of the given strings.Auxiliary Space: O(1), no extra space is required, so it is a constant. Comment More infoAdvertise with us Next Article C++ Program to Compare Paths of Two Files B bilal-hungund Follow Improve Article Tags : Strings Technical Scripter C++ Programs DSA cpp-string cpp-pointer +2 More Practice Tags : Strings Similar Reads C++ Program to Compare Paths of Two Files As we are given two paths of two files, we have to compare these two paths and check whether they are equal or greater or smaller using a C++ program. Input: path1 = "/a/b/c" , path2 = "/a/b/" Output: path1 is greater than path2Approaches:Using built-in compare function :To store paths use string as 5 min read How to Sort an Array of Strings Using Pointers in C++? In C++, sorting an array of strings using pointers is quite different from normal sorting because here the manipulation of pointers is done directly, and then according to which string is pointed by the pointer the sorting is done. The task is to sort a given array of strings using pointers. Example 2 min read C++ Program to Sort String of Characters Sorting a string means rearranging the characters of the given string in some defined order such as alphabetical order. In this article, we will learn how to sort a string by characters in C++.ExamplesInput: str = "geeksforgeeks"Output: "eeeefggkkorss"Explanation: The characters in the string are so 4 min read How to Compare Two Lists in C++ STL? In C++, lists are containers provided by the STL library of C++, which allows us to store elements of the same data type in non-contiguous memory locations. Comparing two lists is a very common operation while using lists. In this article, we will learn how to compare two lists in C++. Example: Inpu 2 min read C++ Program For Comparing Two Strings Represented As Linked Lists Given two strings, represented as linked lists (every character is a node in a linked list). Write a function compare() that works similar to strcmp(), i.e., it returns 0 if both strings are the same, 1 if the first linked list is lexicographically greater, and -1 if the second string is lexicograph 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