Strings

  1. 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?
    1. even palindrome
    2. odd palindrome
    3. both even and odd
    4. none of the above
  1. View Hint | View Answer | Workspace | Discuss In Forum | Report

    example of an odd palindrome:-
    madam
    Level
    example of an even palindrome:-
    noon

    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

    Report