free function in c code example

Example 1: free in c

the C library function void free(void *ptr) 
  deallocates the memory previously allocated by a call to calloc, malloc, or realloc.

Example 2: c malloc array

#define ARR_LENGTH 2097152
int *arr = malloc (ARR_LENGTH * sizeof *arr);

Example 3: what is the use of malloc in c

In C, the library function malloc is used to allocate a block of memory on the heap. The program accesses this block of memory via a pointer that malloc returns. When the memory is no longer needed, the pointer is passed to free which deallocates the memory so that it can be used for other purposes.

Tags:

Misc Example