Segmentation fault on large array sizes

后端 未结 5 1829
醉梦人生
醉梦人生 2020-11-21 04:33

The following code gives me a segmentation fault when run on a 2Gb machine, but works on a 4GB machine.

int main()
{
   int c[1000000];
   cout << \"do         


        
5条回答
  •  悲哀的现实
    2020-11-21 05:13

    Because you store the array in the stack. You should store it in the heap. See this link to understand the concept of the heap and the stack.

提交回复
热议问题