Differences between using realloc vs. free -> malloc functions

前端 未结 5 1010
自闭症患者
自闭症患者 2020-12-23 19:59

Why would one use realloc() function to resize an dynamically allocated array rather than using free() function before calling the malloc() function again (i.e. pros and con

5条回答
  •  甜味超标
    2020-12-23 20:39

    "rather than using free() function before calling the malloc() function again"

    If you free the existing array, you've lost all of its contents, so you cannot "grow" the array in the usual sense.

提交回复
热议问题