Is it good coding practice to assign the address returned by realloc() to the same pointer?
问题 I saw some code related to realloc() on some sites as below. int *p = (int *)malloc(sizeof(int) * 10); p = (int *)realloc(p, 100); But as the standard says, if realloc fails, the original block is left untouched and it returns NULL. So if realloc fails, from above example, we will lose the ability to free p. Can any one please let me know is it good coding practice to assign the address returned by realloc() to the same pointer? 回答1: You are correct that directly assigning the return value of