Does C allocate memory automatically for me?

前端 未结 8 2136
情话喂你
情话喂你 2020-12-19 14:18

I have been writing C for only a scant few weeks and have not taken the time to worry myself too much about malloc(). Recently, though, a program of mine return

8条回答
  •  星月不相逢
    2020-12-19 14:34

    My question is, how does C allocate memory when I haven't actually malloc()ed the appropriate amount of memory? What's the default?

    To not allocate memory. You have to explicity create it on the stack or dynamically.

    In your example, subcells points to an undefined location, which is a bug. Your function should return a pointer to a Cell struct at some point.

提交回复
热议问题