1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What is a recursive function?

Discussion in 'C' started by desiram, Nov 16, 2006.

  1. desiram

    desiram New Member

    Joined:
    Nov 16, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Write a program that uses a recursive function to determine if a string is a palindrome
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    Recursion in computer programming defines a function in terms of itself.A function that calls itself repeatedly, satisfying some condition is called a Recursive Function. Using recursion, we split a complex problem into its single simplest case. The recursive function only knows how to solve that simplest case.

    To view a few recursion examples checkout this thread http://www.go4expert.com/showthread.php?t=1527&highlight=recursion
     
  3. dhanulakshmi

    dhanulakshmi New Member

    Joined:
    Nov 29, 2006
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    recursive function is nothing but the function calls itself untill the given condition fails...but these recursive functions aren`t that much recomended ,because they will occupy more stack space...i.e genarally when the function is called it occupies one stack frame....when recursive functions are used more more stack sapce is allocated to complete the stack....

    code for recursive function to reverse the string ....
    strev(char *str)
    {
    if(*str++!='\0')
    {
    strev(str);
    }
    printf("%s",*--str);
    }

    can u guess what is happening in the above program...as the strev is called recursively....it is occupieing stack frames char by char...as the stack works on LIFO principle....while retriving it prints in reverse order....then u can check..whether the given string and resulted strings are equal are not....if they are equal guven string is palindrome
     
  4. Aztec

    Aztec New Member

    Joined:
    May 9, 2006
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    0
    Correct.
    Most of the time iterative solution is better than recursive one.
     

Share This Page