realloc()
BrandonDusch580 total contributions
Published Aug 18, 2022Updated Aug 19, 2022
Contribute to Docs
The realloc()
function is used to reallocate a block of memory. If the memory that was previously allocated using the malloc()
or calloc()
function is not sufficient, it can be reallocated using the realloc()
function.
Syntax
realloc(memoryblock, size);
The memoryblock
must exist beforehand. The size
is of type size_t
.
Example
The following example showcases the realloc()
function:
int *ptr;// Memory allocated using malloc() functionptr = (int*) malloc(5 * sizeof(int));// ptr is reallocated with 40 bytes (4 * 10) of memoryptr = realloc(ptr, 10 * sizeof(int));
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.