Check String is Palindrome C Program

By | August 27, 2016

C Program To Check if String is Palindrome or Not

Learn How To Check if a String is Palindrome or Not in C Programming. This C Program To check whether the given string is palindrome makes use of While Loop and For Loop.

What is a Palindromic String?

A string is said to be a palindromic string if it is identical to the original string after the String has been reversed. This code makes use of two string functions viz., strrev(), strlen() and strcmp(). Initially, the string is reversed and then compared with the original string if it is palindrome or not.



Must Read: C Program To Reverse A String without using Functions

C Program To Check if String is Palindrome or Not using String Functions


int main()
      int length = 0, count;
      char str1[40], str2[40], temp;
      printf("\nEnter a String: \t");
      scanf("%s", str1);
      printf("\nOriginal String: \t%s\n", str1);
      length = strlen(str1) - 1;
      strcpy(str2, str1);
      for(count = 0; count < length; count++, length--)
            temp = str1[count];
            str1[count] = str1[length];
            str1[length] = temp;
      printf("\nString After Reversal: \t%s\n", str1);
      if(strcmp(str1, str2) == 0)
            printf("\nStrings are identical and Palindrome\n");
            printf("\nStrings are Not Palindrome\n");
      return 0;

Must Read: C Program To Arrange Names in Alphabetical Order



C Program To Check if String is Palindrome or Not using Functions strlen, strrev, strcmp

If you have any compilation errors or doubts in this C Program to Check if a given String is Palindromic or Not, let us know about it in the Comment Section below.

2 thoughts on “Check String is Palindrome C Program

  1. Vishal Mehta

    Is it necessary to use strlen method? Can we not directly loop till the limit of the array?

  2. Devraj Royy

    What does the strcmp function do there? Is it important to use strlen() function to find palindromic string?


Let's Discuss