What is the correct usage of realloc() when it fails and returns NULL?

后端 未结 4 1865
Happy的楠姐
Happy的楠姐 2020-12-31 04:39

Can anyone summarize what is the correct usage of realloc()?

What do you do when realloc() fails?

From what I have seen so far, it

4条回答
  •  臣服心动
    2020-12-31 05:23

    If realloc fails I don't think you would want to delete the original block since you will lose it. It seems like realloc will resize the old block (or return a pointer to a new location) and on success will return a pointer to the old block (or new location) and on failure will return NULL. If it couldn't allocate a new block the old block is untouched.

提交回复
热议问题