Skip to content
Related Articles
Open in App
Not now

Related Articles

Difference between Static and Dynamic Memory Allocation in C

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 12 Aug, 2021
Improve Article
Save Article

Memory Allocation: Memory allocation is a process by which computer programs and services are assigned with physical or virtual memory space. The memory allocation is done either before or at the time of program execution. There are two types of memory allocations: 

  1. Compile-time or Static Memory Allocation
  2. Run-time or Dynamic Memory Allocation

Static Memory Allocation: Static Memory is allocated for declared variables by the compiler. The address can be found using the address of operator and can be assigned to a pointer. The memory is allocated during compile time. 

Dynamic Memory Allocation: Memory allocation done at the time of execution(run time) is known as dynamic memory allocation. Functions calloc() and malloc() support allocating dynamic memory. In the Dynamic allocation of memory space is allocated by using these functions when the value is returned by functions and assigned to pointer variables. 


Tabular Difference Between Static and Dynamic Memory Allocation in C:



Static Memory Allocation

Dynamic Memory Allocation

1In the static memory allocation, variables get allocated permanently, till the program executes or function call finishes.In the Dynamic memory allocation, variables get allocated only if your program unit gets active.
2Static Memory Allocation is done before program execution.Dynamic Memory Allocation is done during program execution.
3It uses stack for managing the static allocation of memoryIt uses heap for managing the dynamic allocation of memory
4It is less efficientIt is more efficient
5In Static Memory Allocation, there is no memory re-usabilityIn Dynamic Memory Allocation, there is memory re-usability and memory can be freed when not required
6In static memory allocation, once the memory is allocated, the memory size can not change.In dynamic memory allocation, when memory is allocated the memory size can be changed.
7In this memory allocation scheme, we cannot reuse the unused memory.This allows reusing the memory. The user can allocate more memory when required. Also, the user can release the memory when the user needs it.
8In this memory allocation scheme, execution is faster than dynamic memory allocation.In this memory allocation scheme, execution is slower than static memory allocation.
9In this memory is allocated at compile time.In this memory is allocated at run time.
10In this allocated memory remains from start to end of the program.In this allocated memory can be released at any time during the program.
11Example: This static memory allocation is generally used for array.Example: This dynamic memory allocation is generally used for linked list.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!