0% found this document useful (0 votes)
49 views23 pages

Dynamic Memory Allocation in C

Dynamic memory allocation is the process of allocating memory at runtime to optimize memory usage and reduce wastage. In C, memory allocation is divided into four segments: Code, Variables (which includes initialized and uninitialized data), and Stack. The stack operates as a LIFO data structure, growing as the program executes.

Uploaded by

nkarn5789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views23 pages

Dynamic Memory Allocation in C

Dynamic memory allocation is the process of allocating memory at runtime to optimize memory usage and reduce wastage. In C, memory allocation is divided into four segments: Code, Variables (which includes initialized and uninitialized data), and Stack. The stack operates as a LIFO data structure, growing as the program executes.

Uploaded by

nkarn5789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Data Structures & Algorithms

Dynamic Memory
Allocation
Dynamic Memory Allocation

What is Dynamic memory?

• Dynamic memory allocation is the process of allocation of memory space at


the run time.
• We use the concept of dynamic memory allocation to reduce the wastage of
memory, and it is the optimal way of memory allocation.
Dynamic Memory Allocation

Memory Allocation in C

Memory allocation in C can be divided into four segments.


1) Code:
• Code composes of all the text segment of our program.
2) Variables:
• By variables, we mean both global and static variables. Global variables can
be used anywhere in the program, while static has its limitations inside the
function.
• The variable segment is further divided into two segments, depending on
the data they can store.
Dynamic Memory Allocation

Memory Allocation in C

2a) Data segment: stores initialized data i.e., data whose value is already
given.
• For example:

2b) bss segment: stores uninitialized data i.e., data whose variable is initialized
only.
• For example:
Dynamic Memory Allocation

Memory Allocation in C

3) Stack:
The stack is a LIFO data structure. It's size increases when the program moves
forward.
gcc filename.c ; size .\[Link]
Thank You

You might also like