segmentation fault 11 in C++ on Mac

前端 未结 2 1736
闹比i
闹比i 2021-02-08 13:28

When I try to run this

int N=10000000;
short res[N];

I get segmentation fault 11

when I change to

int N=1000000;
short         


        
2条回答
  •  一生所求
    2021-02-08 13:47

    You can't allocate all that on the stack. Try short* res = new short[10000000]; and don't forget to clean up.

    Alternatively, you can use std::vector res(10000000);

提交回复
热议问题