void* realloc(void* buffer, int size)


A pointer to a previously allocated memory block.
The size of the memory to be reserved, measured in bytes.


A pointer to the allocated memory.


Resizes an amount of memory previously reserved by means of calloc or malloc to size number of bytes whilst retaining any information already in the buffer (so far as the new size specified permits).
If the memory could be allocated, a pointer to the first element in the reserved memory block is returned, memory may be moved around so the previously used pointer should be considered invalid after use in this function.
If the memory could not be allocated (i.e. due to memory shortage or a high degree of memory fragmentation), a NULL value is returned instead. Please note that should this happen, the original memory block is left untouched and must be freed manually.
When specifying a NULL pointer, this function works identical to malloc.
When specifying a new size of 0, memory is effectively freed and a NULL is returned since no memory is allocated.
Any memory reserved by use of this function must be manually deallocated by means of the free function, failure to do so will result in memory leakage and will ultimately crash the system.



    // Allocate a string for 255 characters.
    char* buffer_1 = malloc(255);

    // We need some more memory, 512 characters will do.
    char* buffer_2 = realloc(buffer_1, 512);


Also see

calloc, free, malloc