VOOZH about

URL: https://www.geeksforgeeks.org/cpp/c-program-to-check-if-a-given-string-is-palindrome-or-not/

⇱ C++ Program to Check if a Given String is Palindrome or Not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C++ Program to Check if a Given String is Palindrome or Not

Last Updated : 31 Mar, 2026

A string is said to be a palindrome if the reverse of the string is the same as the original string. For Example: string "AABBAA" is a palindrome because its reversed form is identical to the original string.

Below are some methods to check if a string is palindrome or not:

Comparing with Reversed String

A string is a palindrome if it reads the same forwards and backwards, this can be checked by reversing the string using std::reverse() and comparing it with the original.


Output
"ABCDCBA" is palindrome.
"ABCD" is NOT palindrome.

Explanation:

  • The function isPalindrome() takes a string and creates its reversed copy using reverse().
  • It then compares the original string with the reversed string.
  • If both are equal, the string is a palindrome, otherwise, it is not.

Using Two Pointer Method

In this method, we place the two index pointers, left and right at the starting and ending character of the string respectively. After that, we start matching the character present at left and right position.

  • If the characters match, we will increment left and decrement right.
  • This process will repeat till left is less than right. If left will become greater than or equal to right, then the string is palindrome.
  • If at any point the character does not match, then string is not palindrome.

Code Implementation:


Output
"ABCDCBA" is palindrome.
"ABCD" is NOT palindrome.
Comment