What is a recursive function?

desiram's Avatar, Join Date: Nov 2006
Newbie Member
Write a program that uses a recursive function to determine if a string is a palindrome
pradeep's Avatar, Join Date: Apr 2005
Team Leader
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....ight=recursion
dhanulakshmi's Avatar
Light Poster
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
Aztec's Avatar, Join Date: May 2006
Contributor
Quote:
Originally Posted by dhanulakshmi
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..
Correct.
Most of the time iterative solution is better than recursive one.