Freeing allocated memory: realloc() vs. free()

前端 未结 7 1156
醉梦人生
醉梦人生 2020-12-10 04:05

so I have a piece of memory allocated with malloc() and changed later with realloc().

At some point in my code I want to empty it, by this

7条回答
  •  庸人自扰
    2020-12-10 04:45

    void* realloc (void* ptr, size_t size);
    

    In C90 :

    if size is zero, the memory previously allocated at ptr is deallocated as if a call to free was made, and a null pointer is returned.

    In C99:

    If size is zero, the return value depends on the particular library implementation: it may either be a null pointer or some other location that shall not be dereferenced.

提交回复
热议问题