Jump to: navigation, search


Declared in stdlib.h

void *malloc(size_t n);
void *realloc(void *p, size_t n);
void *calloc(size_t nmemb, size_t size);
void free(void *p);


The malloc function allocates n bytes of memory, suitably aligned for storage of any type. This pointer is suitable for passing to free, which deallocates it, or realloc, which changes its size (and may move it to a different location). calloc allocates nmemb*size bytes, as if by malloc, and sets them to all bits zero.

It should be noted that all bits zero is not necessarily a valid null pointer or floating point 0 so calloc cannot be relied upon to correctly initialise all data types.

Return value

malloc, realloc, and calloc return NULL if not enough memory was available for the requested operation. If realloc returned NULL due to not enough memory available, the original pointer is still allocated with its original size.

It's implementation-defined whether NULL is returned when zero bytes are requested!

See also


Personal tools