How to check whether a given string is a palindrome or not?

Problem - If the reversed integer is equal to the integer entered by user then, that number is a palindrome if not that number is not a palindrome. We need to check if a string passed is a palindrome.

Example -

“madam” is a palindromic string because it reads the same forwards and backward. Other palindromic strings are “anna,” “civic,” “level,”.

Using reverse() and strlen() this problem is simplified in the video.

Approach used is -

  1. First take a string as input.
  2. Compare the first and the last character of the string. If they are equal, then compare the second and the second last character of the string, and so on, until we get to the middle of the string.
  3. If the characters do not match at any iteration, then the string is not a palindrome.