11.04.2009

malloc vs calloc vs realloc

char* malloc(sizeOf)
Returns a pointer in the heap with the specified size. One major difference is that it does not initialize the memory.

char* calloc(numElements, sizeOfElement)
Returns a pointer in the heap with the specified size for a number of elements - usually for an array.

char* realloc(ptr, newSize)
Returns a pointer in the heap after growing or shrinking a block a memory that was allocated by using malloc, calloc or realloc.

void free(ptr)
No return value. Deallocates memory previous allocated by malloc, calloc or realloc. ptr is unchanged.

No comments:

Post a Comment