[Ilugc] C pgm - Recursive -segmentation fault
- From: praveen@xxxxxxxxxxx (Praveen)
- Date: Mon Sep 13 17:16:51 2004
Chakravarthi_Mohan wrote:
void R()
{
static int i =0;
i++;
printf("%d\n",i);
R();
}
int main()
{
R();
}
What is the problem here?
For any recursive function, you should have an exit criteria. Otherwise
it would recurse forever. Your function doesn't have an exit point.
When I run this program, Recursive Function R(),
Called only 523714 times, after that segmentation fault occurs WHY?
Since you don't have an exit point, repeated call of the function by itself
leads to stack overflow.
HTH.
--
Praveen Kumar
Web :
http://myriad-zero.net
Blog :
http://blog.myriad-zero.net
Mobile : +91-98407-02060
Other related posts: