Table of Contents        Previous topic       Next topic       

C COMPILER LIBRARY FUNCTIONS->Detailed Descriptions->realloc()


#include <malloc.h>

void realloc(void memblock, size_t size);Reallocate a block of memory


memblockPointer to the previously allocated block
sizeBytes required in new allocated block


The realloc() function changes the size of a previously allocated memory block pointed to by memblock.  If memblock is NULL, realloc() behaves the same way as malloc() and allocates a new block of size bytes.  Otherwise memblock should be a pointer returned by a prior call to malloc() or

The size argument gives the new size of the block in bytes.  The contents of the block are unchanged up to the shorter of the new and old sizes.

The new block may be in a different location to the original block and so the pointer returned by realloc() may be different to the pointer passed through the memblock argument.

If size is zero and memblock is not NULL, the original memory block is freed.

Return Value

The function returns a void pointer to the allocated (and possibly moved) space.  NULL is returned if size is zero and memblock is not NULL or if there is insufficient memory available to expand the block to the required size.