Reallocate Memory
If the amount of memory you reserved is not enough, you can reallocate it to make it larger.
Reallocating reserves a different (usually larger) amount of memory while keeping the data that was stored in it.
You can change the size of allocated memory with the realloc()
function.
The realloc()
function takes two parameters:
int *ptr2 = realloc(ptr1, size);
- The first parameter is a pointer to the memory that is being resized.
- The second parameter specifies the new size of allocated memory, measured in bytes.