Course Hubs
Articles
Sign in

Dynamic Memory Allocation in C
Learn about dynamic memory allocation in C.
A
Abhishek Chandra
17 Dec 2021-21 mins read
Abstract
When we declare a variable or an array of any data type the space occupied by them in the system's memory remains constant throughout the execution of the program. Sometimes the constant space allocated at the compile-time may fall short, and to increase the space during run-time we came through the concept of Dynamic Memory Allocation. Allocation and Deallocation of memory at run-time in C are done using the concept of Dynamic Memory Allocation. It is a method in which we use different library functions like malloc(), calloc(), realloc(), and free() to allocate and deallocate a memory block during run-time.
It is considered as a very important topic because almost every Data Structure (such as Linked Lists, Stack, Queue, Trees, etc.) is associated with the concept of Dynamic Memory Allocation.
Scope
This article briefly explains memory management and how to allocate memory at run-time in C Language using various library functions.
This article introduces you to the concept of Dynamic Memory Allocation with examples.
How Does Memory Management in C works?
To understand memory management in C, we first have to learn about the types of memory that are used during the execution of a C Program .
There are two types of memory in our machine, one is Static Memory and another one is Dynamic Memory; both the memory are managed by our Operating System. Our operating system helps us in the allocation and deallocation of memory blocks either during compile-time or during the run-time of our program.
When the memory is allocated during compile-time it is stored in the Static Memory and it is known as Static Memory Allocation, and when the memory is allocated during run-time it is stored in the Dynamic Memory and it is known as Dynamic Memory Allocation.
Now, let us see some differences in Static Memory Allocation and Dynamic Memory Allocation.

Course Hubs
Articles
Sign in

Dynamic Memory Allocation in C
Learn about dynamic memory allocation in C.
A
Abhishek Chandra
17 Dec 2021-21 mins read
Abstract
When we declare a variable or an array of any data type the space occupied by them in the system's memory remains constant throughout the execution of the program. Sometimes the constant space allocated at the compile-time may fall short, and to increase the space during run-time we came through the concept of Dynamic Memory Allocation. Allocation and Deallocation of memory at run-time in C are done using the concept of Dynamic Memory Allocation. It is a method in which we use different library functions like malloc(), calloc(), realloc(), and free() to allocate and deallocate a memory block during run-time.
It is considered as a very important topic because almost every Data Structure (such as Linked Lists, Stack, Queue, Trees, etc.) is associated with the concept of Dynamic Memory Allocation.
Scope
This article briefly explains memory management and how to allocate memory at run-time in C Language using various library functions.
This article introduces you to the concept of Dynamic Memory Allocation with examples.
How Does Memory Management in C works?
To understand memory management in C, we first have to learn about the types of memory that are used during the execution of a C Program .
There are two types of memory in our machine, one is Static Memory and another one is Dynamic Memory; both the memory are managed by our Operating System. Our operating system helps us in the allocation and deallocation of memory blocks either during compile-time or during the run-time of our program.
When the memory is allocated during compile-time it is stored in the Static Memory and it is known as Static Memory Allocation, and when the memory is allocated during run-time it is stored in the Dynamic Memory and it is known as Dynamic Memory Allocation.
Now, let us see some differences in Static Memory Allocation and Dynamic Memory Allocation.
Static Memory AllocationDynamic Memory AllocationConstant (Invariable) memory is reserved at compile-time of our program that can't be modified.Dynamic (Variable) memory is reserved at run-time of our program that can be modified.It is used at compile-time of our program and is also known as compile-time memory allocation.It is used at run-time of our program and is also known as run-time memory allocation.We can't allocate or deallocate a memory block during run-time.We can allocate and deallocate a memory block during run-time.Stack space is used in Static Memory Allocation.Heap space is used in Dynamic Memory Allocation.It doesn't provide reusability of memory, while the program is running. So, it is less efficient.It provides reusability of memory, while the program is running.
Sur cette page du site, vous pouvez voir la vidéo en ligne Dynamic Memory Allocation | Heap Memory | Malloc in C Programming durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Frustrated Londa 20 février 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 243 fois et il a aimé 8 téléspectateurs. Bon visionnage!