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.
Example
madam
Must Read: C Program To Reverse A String without using Functions
C Program To Check if String is Palindrome or Not using String Functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include<stdio.h> #include<string.h> 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"); } else { printf("\nStrings are Not Palindrome\n"); } return 0; } |
Must Read: C Program To Arrange Names in Alphabetical Order
Output

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.
Is it necessary to use strlen method? Can we not directly loop till the limit of the array?
What does the strcmp function do there? Is it important to use strlen() function to find palindromic string?