-- advertisement --

Discussion

  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. 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


Your comments will be displayed only after manual approval.

-- advertisement --

-- advertisement --