realloc
is used to reallocate the memory dynamically.
Suppose I have allocated 7 bytes using the malloc
function and now I want to extend i
From the man page:
realloc() returns a pointer to the newly allocated memory, which is suitably aligned for any kind of variable and may be different from ptr, or NULL if the request fails.
So in other words, to detect failure, just check whether the result was NULL.
EDIT: As noted in the comment, if the call fails, the original memory isn't freed.