Recursive main() - why does it segfault?

后端 未结 6 797
青春惊慌失措
青春惊慌失措 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:20

    Because every time it calls itself it allocates a little bit of stack space; eventually it runs out of stack space and segfaults. I'm a bit surprised it goes with a segfault, though; I would have expected (drum roll) stack overflow!

提交回复
热议问题