Thursday, 20 March 2014

DYNAMIC MEMORY ALLOCATION

• Dynamic memory allocation
– we  Can create dynamic arrays using dynamic memory alloaction.
 
 
•  calloc(nmembers, size)
– nmembers – number of members
– size – size of each member
– it Returns pointer to dynamic array for memory allocation.
 
• realloc(pointerToObject, newSize)
– pointerToObject – pointer to the object being reallocated
– newSize – new size of the object
– Returns pointer to reallocated memory
– Returns NULL if cannot allocate space
– If newSize = 0, object freed
–If pointerToObject = 0, acts like malloc

No comments:

Post a Comment