The function may move the memory block to a new location, in which case the new location is returned.
For example I have a pointer to an array:
int *arr; // somewhere next it initialized, filled with elements and etc
Somewhere I need to:
void* location = realloc(arr, NEW_SIZE);
What will happen with old memory block place?
If realloc return pointer that not math to arr, should i use next code?:
delete arr;
arr = (int*)location;
realloc(void *ptr, size_t new_size) requires the given area of memory that
ptrpoints to to be previously allocated by malloc(), calloc() or realloc() and not yet freed with free(), otherwise, the results are undefined.Use realloc only with malloc, calloc or another realloc and clean it up with free.
In C++ use always new with delete and new[] with delete[].