Segmentation fault when allocating large arrays on the stack

后端 未结 2 1461
旧巷少年郎
旧巷少年郎 2020-12-07 02:17

When I compiled this simple C code it\'s fine but after uncommenting the line it shows segmentation fault. I don\'t know what\'s wrong with this. Please help.



        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 03:09

    Variables allocated inside a function are put on the stack, which has a limited size. You can allocate them on the (larger) heap instead by using malloc.

提交回复
热议问题