The function changes the size of the memory block pointed to by ptr to size bytes. The contents will be unchanged in the range from the start of the region up to the minimum of the old and new sizes. If the new size is larger than the old size, the added memory will not be initialized. If ptr is NULL, then the call is equivalent to malloc(size), for all values of size; if size is equal to zero, and ptr is not NULL, then the call is equivalent to free(ptr). Unless ptr is NULL, it must have been returned by an earlier call to malloc(), —Āalloc(), or reallocarray(). If the area pointed to was moved, a free(ptr) is done. realloc(ptr, size)
ptr: pointer to already allocated memory arrea. size: size of needed arrea. The function returns a pointer to the newly allocated memory, which is suitably aligned for any built-in type, or NULL if the request failed. The returned pointer may be the same as ptr if the allocation was not moved (e.g., there was room to expand the allocation in-place), or different from ptr if the allocation was moved to a new address. If size was equal to 0, either NULL or a pointer suitable to be passed to free() is returned. If fails, the original block is left untouched; it is not freed or moved.