Tuesday, February 14, 2012

What is free() in C?

free() frees the allocated memory space pointed to ptr, which must have been returned by a previous call to malloc(), calloc() or realloc(). Otherwise, or if free(ptr) has already been called before, undefined behaviour occurs. If ptr is NULL, no operation is performed.

void free(void *ptr);

char *ptr;
ptr = (char *)calloc(10,sizeof(char));

memory leak occurs if you are not freeing the allocated memory.

No comments:

Popular Posts