Why infinite recursion leads to seg fault

后端 未结 8 2222
长情又很酷
长情又很酷 2020-12-04 01:42

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()
{
           


        
8条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 02:11

    Segmentation fault is a condition when your program tries to access a memory location that it is not allowed to access. Infinite recursion causes your stack to grow. And grow. And grow. Eventually it will grow to a point when it will spill into an area of memory that your program is forbidden to access by the operating system. That's when you get the segmentation fault.

提交回复
热议问题