📜  realloc - 任何代码示例

📅  最后修改于: 2022-03-11 14:55:08.794000             🧑  作者: Mango

代码示例1
int ptr_new = *realloc(void *ptr, size_t size); 
Where 'ptr_new' is the new pointer you want to point to the required Dynamic
memory, 'ptr' is the already existing pointer to a dynamic memory and 'size'
is the new size of dynamic memory that you want to allocate.

Working:
Realloc creates/allocates a new memory in heap with specified size and copies
all the contents from the previous memory pointer to by the pointer 'ptr'.
It the deallocates the memory in heap pointed to by the old pointer i.e, 'ptr'.
Note: pointer 'ptr' should also point to a memory in heap.