Recursive main() - why does it segfault?

后端 未结 6 778
青春惊慌失措
青春惊慌失措 2021-01-02 07:49

Why does the following program segfault?

int main() { main(); }

Even though it is a recursion that does not end and is therefore invalid by

6条回答
  •  情歌与酒
    2021-01-02 08:14

    Each function call add entires in stack and this entries will get removed from stack when function exit. Here we have recursive function call which doesn't have exit condition. So its a infinite number of function call one after another and this function never get exit and there entires never removed from the stack and it will lead to Stack overflow.

提交回复
热议问题