free()

Deallocates memory previously allocated by malloc, calloc, or realloc. Prevents memory leaks.

Syntax

c
void free(void *ptr)

Example

c
int *data = malloc(100 * sizeof(int));
// ... use data ...
free(data);
data = NULL; // good practice after free

// free(NULL) is safe — does nothing
free(NULL);