Can you give an example of stack overflow in C++?

后端 未结 12 1568
不知归路
不知归路 2020-12-31 18:52

Can you give an example of stack overflow in C++? Other than the recursive case:

void foo() { foo(); }
12条回答
  •  北海茫月
    2020-12-31 19:41

    As per edit :-)

    void ping()
    {
      pong();
    }
    
    void pong()
    {
    ping();
    }
    

    Also, I believe you can get stack overflow if you try to allocate more space than maximum thread stack size ( 1MB by default in VS), so something like int a[100000]; should provide the exception.

提交回复
热议问题