C - Dynamic Memory Allocation

Structure and Linked List with C Programming in Tamil

C Dynamic Memory Allocation

  • In C- Programming the memory will be allocated at runtime called as dynamic memory allocation.
  • Generally, the malloc, calloc and realloc are the three functions used to manipulate memory in C-Programming..
Dynamic memory allocation

Dynamic Memory Allocation functions :

  1. Malloc()
  2. Calloc()
  3. Realloc()
  4. Free()
C Dynamic Memory Allocation

Malloc() Functions :

  • In C-Programming the malloc function is used to allocate space in memory during the execution of the program.

C Syntax

malloc (number *sizeof(int)); 

Calloc() Function :

  • The calloc() function is similar to malloc() function. The calloc () initializes the allocated memory to zero.

C Syntax

calloc (number, sizeof(int)); 

Realloc() Function :

  • In C-Programming the realloc() function modifies the allocated memory size by malloc() and calloc() functions to new size.

C Syntax

realloc (pointer_name, number * sizeof(int)); 

Free() Function :

  • In C-Programming the free () function frees the allocated memory by malloc (), calloc (), realloc () functions and returns the memory to the system.

C Syntax

free (pointer_name);

Static vs Dynamic Memory Allocation

Static Memory Allocation Dynamic Memory Allocation
Memory is allocated at compile time. Memory is allocated at run time.
Memory can't be increased while executing  program. Memory can be increased while executing  program.
Used in array. Used in linked list.
Less efficient More efficient

View More Quick Examples

Related Searches to c dynamic memory allocation