Dynamic Memory Management
Dynamic Memory Management
Return value: void pointer (void *). void pointer (void *).
If the allocation succeeds, a If the allocation succeeds, a
pointer to the block of memory pointer to the block of memory
is returned. is returned.
©LPU CSE101 C Programming
realloc()
• Now suppose you've allocated a certain number of
bytes for an array but later find that you want to add
values to it. You could copy everything into a larger
array, which is inefficient, or you can allocate more
bytes using realloc(), without losing your data.
• realloc() takes two arguments.
1. The first is the pointer referencing the memory.
2. The second is the total number of bytes you want to
reallocate.
• Passing zero as the second argument is the equivalent
of calling free.
• Syntax:
void *realloc(pointerToObject, newsize);