Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Difference between Static and Dynamic Memory Allocation

Static Vs. Dynamic Memory Allocation in C: Explore the Difference between Static and Dynamic Memory Allocation

In programming, the term memory allocation plays a vital role. Basically, it is a process by which a particular computer program is allocated memory space. There are two types of memory allocations. Static and dynamic. Let’s find out some major differences between static and dynamic memory allocation in C.

What is Static Memory Allocation?

When the allocation of memory performs at the compile time, then it is known as static memory. In this, the memory is allocated for variables by the compiler.

What is Dynamic Memory Allocation?

When the memory allocation is done at the execution or run time, then it is called dynamic memory allocation.

Difference between Static and Dynamic Memory Allocation

S.No Static Memory Allocation Dynamic Memory Allocation
1 When the allocation of memory performs at the compile time, then it is known as static memory. When the memory allocation is done at the execution or run time, then it is called dynamic memory allocation.
2 The memory is allocated at the compile time. The memory is allocated at the runtime.
3 In static memory allocation, while executing a program, the memory cannot be changed. In dynamic memory allocation, while executing a program, the memory can be changed.
4 Static memory allocation is preferred in an array. Dynamic memory allocation is preferred in the linked list.
5 It saves running time as it is fast. It is slower than static memory allocation.
6 Static memory allocation allots memory from the stack. Dynamic memory allocation allots memory from the heap.
7 Once the memory is allotted, it will remain from the beginning to end of the program. Here, the memory can be alloted at any time in the program.
8 Static memory allocation is less efficient as compared to Dynamic memory allocation. Dynamic memory allocation is more efficient as compared to the Static memory allocation.
9 This memory allocation is simple. This memory allocation is complicated.

Keep learning and stay tuned to BYJU’S to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2024, GATE Admit Card, GATE Application Form, GATE Syllabus, GATE Cutoff, GATE Previous Year Question Paper, and more.

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*