Back

ⓘ C dynamic memory allocation




                                     

ⓘ C dynamic memory allocation

In the C programming language, dynamic memory allocation refers to allocating memory during a programs run time. Dynamically allocated memory is obtained from a storage pool called a heap. A group of functions in the C standard library are typically used for dynamic memory allocation.

                                     

1. Overview of functions

C dynamic memory allocation functions are defined in stdlib.h header.

Differences between malloc and calloc

  • malloc takes a single argument the amount of memory to allocate in bytes, while calloc needs two arguments the number of variables to allocate in memory, and the size in bytes of a single variable.
  • malloc does not initialize the memory allocated, while calloc guarantees that all bytes of the allocated memory block have been initialized to 0.