Synopsis
#include <stdlib.h>
void *realloc(void *ptr, size_t size);
Description

realloc deallocates the old object pointed to by ptr and returns a pointer to a new object that has the size specified by size. The contents of the new
object is identical to that of the old object prior to deallocation, up to the lesser of the new and old sizes. Any bytes in the new object beyond the size of the old object have indeterminate values.

If ptr is a null pointer, realloc behaves like malloc for the specified size. If memory for the new object cannot be allocated, the old object is not deallocated and its value is unchanged.

realloc function returns a pointer to the new object (which may have the same value as a pointer to the old object), or a null pointer if the new object could not be allocated.

Notes

If ptr does not match a pointer earlier returned by calloc, malloc, or realloc, or if the space has been deallocated by a call to free or realloc, the behaviour is undefined.

Portability

realloc conforms to ISO/IEC 9899:1990 (C90) and ISO/IEC 9899:1999 (C99).