Why infinite recursion leads to seg fault ? Why stack overflow leads to seg fault. I am looking for detailed explanation.
int f()
{
f();
}
int main()
{
f();
}
See Question&Answers more detail:osWhy infinite recursion leads to seg fault ? Why stack overflow leads to seg fault. I am looking for detailed explanation.
int f()
{
f();
}
int main()
{
f();
}
See Question&Answers more detail:osEvery time you call f(), you increase the size of the stack - that's where the return address is stored so the program knows where to go to when f() completes. As you never exit f(), the stack is going to increase by at least one return address each call. Once the stack segment is full up, you get a segfault error. You'll get similar results in every OS.