-
Read the following program.
findPalindrome { char *str; char *str1; str = str1; while(str1 != NULL) { str1++; } while(str!=NULL) { if(str1--!= str++) { printf("Not palindrome"); return } } printf("Palindrome"); }
This function will work correctly for which string?
-
- even palindrome
- odd palindrome
- both even and odd
- none of the above
Correct Option: C
take example of string "madam" for odd palindrome.
str points to beginning of the string 'm'
str1 points to end of string 'm'
1st iteration, it is equal.
2nd iteration - 'a'
3rd iteration - 'd'
4th iteration - 'a'
5th iteration - 'm'
similarly consider even palidrome string:- "noon"
str points to beginning of the string 'n'
str1 points to end of string 'n'
2nd iteration-'o'
3rd iteration-'o'
4th iteration-'n'
It works for both even and odd palindromes