# What is a recursive function?

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

1. ### desiramNew Member

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

Joined:
Apr 4, 2005
Messages:
1,646
86
Trophy Points:
0
Occupation:
Programmer
Location:
Kolkata, India
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.

3. ### dhanulakshmiNew Member

Joined:
Nov 29, 2006
Messages:
5
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

Joined:
May 9, 2006
Messages:
90