Dynamic memory allocation in C programming

malloc(Memory allocation)

Allocate dynamic memory.

p = (int *) malloc(n* sizeof(data_type))

calloc(Contigous allocation)

Allocate dynamic memory.

p = (int *) calloc(n, sizeof(data_type))
 

realloc(Reallocation)

Resize the preallocated memory means it will extends the dynamic memory.

p = (int * ) realloc (p, sizeof(data_type)*n)
 

free()

Free allocated memory.

free(p)
© 2016 - 2022, All Rights are Reserved.