Understanding memory allocation, test program crashing

前端 未结 4 1140
南方客
南方客 2020-12-07 02:00

I am just about finished reading K&R, and that is all the C that I know. All my compilation is done from Windows command line using MinGW, and I have no knowledge of ad

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 02:40

    You're running into a stack overflow.

    Local automatic storage variables (such as megabyte) are allocated on the stack, which has limited amount of space. malloc allocates on the heap, which allows much larger allocations.

    You can read more here:

    http://en.wikipedia.org/wiki/Stack_overflow

    (I should note that the C language does not specify where memory is allocated - stack and heap are implementation details)

提交回复
热议问题