How to free memory from char array in C

前端 未结 4 967
生来不讨喜
生来不讨喜 2021-02-01 15:15

I created a char array like so:

char arr[3] = \"bo\";

How do I free the memory associated with array I named \"arr\"?

4条回答
  •  渐次进展
    2021-02-01 15:30

    The memory associated with arr is freed automatically when arr goes out of scope. It is either a local variable, or allocated statically, but it is not dynamically allocated.

    A simple rule for you to follow is that you must only every call free() on a pointer that was returned by a call to malloc, calloc or realloc.

提交回复
热议问题