SlideShare a Scribd company logo
2
Most read
7
Most read
9
Most read
C MEMORY MODEL​
MEMORY MODEL​
• Defines the semantics of computer memory storage for the purpose
of the C abstract machine.​
• The data storage (memory) available to a C program is one or
more contiguous sequences of bytes.
• Each byte in memory has a unique address.​
• Pointers present us with a certain abstraction of the environment
and state in which our program is executed, the C memory model.
C MEMORY MODEL​.pptx
SECTIONS OF MEMORY
• A typical memory representation of a C program consists of
the following sections.​
1. Text segment (i.e. instructions)​
2. Initialized data segment
3. Uninitialized data segment (bss)​
4. Heap
5. Stack​
C MEMORY MODEL​.pptx
TEXT SEGMENT
• A text segment, also known as a code segment or simply as text, is one
of the sections of a program in an object file or in memory, which
contains executable instructions.
• As a memory region, a text segment may be placed below the heap or
stack in order to prevent heaps and stack overflows from overwriting
it.
• Usually, the text segment is sharable so that only a single copy needs
to be in memory for frequently executed programs, such as text
editors, the C compiler, the shells, and so on.
DATA SEGMENT
• The data which we use in our program will be stored in the data
section.
• Since the variables declared inside the main() function are stored in
the stack, but the variables declared outside the main() method will be
stored in the data section.
• The variables declared in the data section could be stored in the form
of initialized, uninitialized, and it could be local or global.
• Therefore, the data section is divided into four categories, i.e.,
initialized, uninitialized, global, or local.
EXAMPLE
int var1;
int var2 = 10;
void function1()
{
printf("I am function1");
}
int main()
{
function1();
return 0;
}
• Here, var1 and var2 variables are declared
outside the main() function where var1 is
the uninitialized variable, whereas the
var2 is an initialized variable.
• These variables can be accessed anywhere
in the program because these variables are
not a part of the main() in the stack.
DATA SEGMENT
• The data segment consists of two segments:
1. Uninitialized data segment: The uninitialized data segment is also
known as a .bss segment that stores all the uninitialized global, local
and external variables. The .bss segment stands for Block Started by
symbol.
char a; // uninitialized global variable..
int main()
{
static int a; // uninitialized static variable..
return 0;
}
DATA SEGMENT
• Initialized data segment: An initialized data segment is also known as
the data segment. A data segment is a virtual address space of a program
that contains all the global and static variables which are explicitly
initialized by the programmer.
char string[] = "javatpoint"; // global variable stored in initiali
zed data segment in read-write area..
int main()
{
static int i = 90; // static variable stored in initialized data seg
ment..
return 0;
}
STACK
• The stack area traditionally adjoined the heap area and grew in the
opposite direction; when the stack pointer met the heap pointer, free
memory was exhausted.
• When we define a function and call that function then we use the stack
frame.
• The stack section plays a very important role in the memory because
whenever the function is called, a new stack frame is created.
• Stack is also used for recursive functions.
HEAP
• Heap memory is used for the dynamic memory allocation.
Heap memory begins from the end of the uninitialized data
segment and grows upwards to the higher addresses.
• The malloc() and calloc() functions are used to allocate the
memory in the heap.
• The heap memory can be used by all the shared libraries and
dynamically loaded modules.
• The free() function is used to deallocate the memory from the
heap.
EXAMPLE
#include<stdio.h>
int main()
{
int *ptr = (int*)malloc(sizeof(int)) ; // memory gets allocated i
n the heap segment.
return 0;
}

More Related Content

PPTX
C dynamic ppt
PPTX
Embedded C programming session10
DOCX
Exception handling in java
PPT
Packages and interfaces
PPTX
Dynamic Memory allocation
PDF
Java - Exception Handling Concepts
PPSX
5bit field
PPTX
COMPILER DESIGN OPTIONS
C dynamic ppt
Embedded C programming session10
Exception handling in java
Packages and interfaces
Dynamic Memory allocation
Java - Exception Handling Concepts
5bit field
COMPILER DESIGN OPTIONS

What's hot (20)

PPTX
Package in Java
PPTX
MACRO ASSEBLER
PPTX
Irony and symbol in waiting for barbarians
PPTX
INTERRUPTS OF 8086 MICROPROCESSOR
PPTX
priority interrupt computer organization
DOCX
Theme of paradise lost
PPTX
sSCOPE RESOLUTION OPERATOR.pptx
PPT
Unit 4 memory system
PPT
Java-java virtual machine
DOC
Dma transfer
PDF
Can Bus communication Protocol
PDF
Basic Computer Organization and Design
PPT
Introduction to Basic C programming 01
PPTX
Segment registers
PPTX
Memory organization in computer architecture
PDF
Topograhical synthesis
PPTX
Database Modeling Using Entity.. Weak And Strong Entity Types
PPT
Exception handling
PDF
Faults in Digital VLSI Circuits
PPT
Software tools
Package in Java
MACRO ASSEBLER
Irony and symbol in waiting for barbarians
INTERRUPTS OF 8086 MICROPROCESSOR
priority interrupt computer organization
Theme of paradise lost
sSCOPE RESOLUTION OPERATOR.pptx
Unit 4 memory system
Java-java virtual machine
Dma transfer
Can Bus communication Protocol
Basic Computer Organization and Design
Introduction to Basic C programming 01
Segment registers
Memory organization in computer architecture
Topograhical synthesis
Database Modeling Using Entity.. Weak And Strong Entity Types
Exception handling
Faults in Digital VLSI Circuits
Software tools
Ad

Similar to C MEMORY MODEL​.pptx (20)

PPTX
How c++ stored in ram
PPTX
Rasperry pi Part 8
PDF
Embedded C - Lecture 3
PDF
Buffer overflow attack
PPT
Linux memorymanagement
PPT
C language
PPT
C language introduction
PPT
C language
PPTX
C++ Memory Management
PPTX
Programming in C.pptx
PDF
C programming language
PPTX
Technical Interview
PPTX
PPTX
Fundamentals of Programming Constructs.pptx
PPT
Stack and heap allocation
PDF
Data structure week 1
PDF
220 runtime environments
PDF
C programming session5
PPT
358 33 powerpoint-slides_3-pointers_chapter-3
How c++ stored in ram
Rasperry pi Part 8
Embedded C - Lecture 3
Buffer overflow attack
Linux memorymanagement
C language
C language introduction
C language
C++ Memory Management
Programming in C.pptx
C programming language
Technical Interview
Fundamentals of Programming Constructs.pptx
Stack and heap allocation
Data structure week 1
220 runtime environments
C programming session5
358 33 powerpoint-slides_3-pointers_chapter-3
Ad

More from SKUP1 (20)

PPTX
serial_busses_i2c.pptx
PPTX
DESIGN PATTERN.pptx
PPTX
INTER PROCESS COMMUNICATION (IPC).pptx
PPTX
DATA STRUCTURES AND LINKED LISTS IN C.pptx
PPTX
C-Programming File-handling-C.pptx
PPTX
Processes, Threads.pptx
PPTX
C-Programming Control statements.pptx
PPTX
Finite State Machine.ppt.pptx
PPTX
FUNCTIONS IN C.pptx
PPTX
cprogramming strings.pptx
PPTX
UNIONS IN C.pptx
PPTX
OPERATORS IN C.pptx
PPTX
cprogramming Structures.pptx
PPTX
C-Programming Function pointers.pptx
PPTX
POINTERS.pptx
PPTX
STACKS AND QUEUES.pptx
PPTX
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
PPTX
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
PPTX
DYNAMIC MEMORY ALLOCATION.pptx
PPTX
COMPILATION PROCESS IN C.pptx
serial_busses_i2c.pptx
DESIGN PATTERN.pptx
INTER PROCESS COMMUNICATION (IPC).pptx
DATA STRUCTURES AND LINKED LISTS IN C.pptx
C-Programming File-handling-C.pptx
Processes, Threads.pptx
C-Programming Control statements.pptx
Finite State Machine.ppt.pptx
FUNCTIONS IN C.pptx
cprogramming strings.pptx
UNIONS IN C.pptx
OPERATORS IN C.pptx
cprogramming Structures.pptx
C-Programming Function pointers.pptx
POINTERS.pptx
STACKS AND QUEUES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
DATATYPES,KEYWORDS,FORMATSPECS[1].pptx
DYNAMIC MEMORY ALLOCATION.pptx
COMPILATION PROCESS IN C.pptx

Recently uploaded (20)

PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPT
Project quality management in manufacturing
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Construction Project Organization Group 2.pptx
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
PPT on Performance Review to get promotions
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Embodied AI: Ushering in the Next Era of Intelligent Systems
Operating System & Kernel Study Guide-1 - converted.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Project quality management in manufacturing
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Construction Project Organization Group 2.pptx
CH1 Production IntroductoryConcepts.pptx
Lecture Notes Electrical Wiring System Components
PPT on Performance Review to get promotions
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Automation-in-Manufacturing-Chapter-Introduction.pdf
Foundation to blockchain - A guide to Blockchain Tech
UNIT-1 - COAL BASED THERMAL POWER PLANTS
UNIT 4 Total Quality Management .pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...

C MEMORY MODEL​.pptx

  • 2. MEMORY MODEL​ • Defines the semantics of computer memory storage for the purpose of the C abstract machine.​ • The data storage (memory) available to a C program is one or more contiguous sequences of bytes. • Each byte in memory has a unique address.​ • Pointers present us with a certain abstraction of the environment and state in which our program is executed, the C memory model.
  • 4. SECTIONS OF MEMORY • A typical memory representation of a C program consists of the following sections.​ 1. Text segment (i.e. instructions)​ 2. Initialized data segment 3. Uninitialized data segment (bss)​ 4. Heap 5. Stack​
  • 6. TEXT SEGMENT • A text segment, also known as a code segment or simply as text, is one of the sections of a program in an object file or in memory, which contains executable instructions. • As a memory region, a text segment may be placed below the heap or stack in order to prevent heaps and stack overflows from overwriting it. • Usually, the text segment is sharable so that only a single copy needs to be in memory for frequently executed programs, such as text editors, the C compiler, the shells, and so on.
  • 7. DATA SEGMENT • The data which we use in our program will be stored in the data section. • Since the variables declared inside the main() function are stored in the stack, but the variables declared outside the main() method will be stored in the data section. • The variables declared in the data section could be stored in the form of initialized, uninitialized, and it could be local or global. • Therefore, the data section is divided into four categories, i.e., initialized, uninitialized, global, or local.
  • 8. EXAMPLE int var1; int var2 = 10; void function1() { printf("I am function1"); } int main() { function1(); return 0; } • Here, var1 and var2 variables are declared outside the main() function where var1 is the uninitialized variable, whereas the var2 is an initialized variable. • These variables can be accessed anywhere in the program because these variables are not a part of the main() in the stack.
  • 9. DATA SEGMENT • The data segment consists of two segments: 1. Uninitialized data segment: The uninitialized data segment is also known as a .bss segment that stores all the uninitialized global, local and external variables. The .bss segment stands for Block Started by symbol. char a; // uninitialized global variable.. int main() { static int a; // uninitialized static variable.. return 0; }
  • 10. DATA SEGMENT • Initialized data segment: An initialized data segment is also known as the data segment. A data segment is a virtual address space of a program that contains all the global and static variables which are explicitly initialized by the programmer. char string[] = "javatpoint"; // global variable stored in initiali zed data segment in read-write area.. int main() { static int i = 90; // static variable stored in initialized data seg ment.. return 0; }
  • 11. STACK • The stack area traditionally adjoined the heap area and grew in the opposite direction; when the stack pointer met the heap pointer, free memory was exhausted. • When we define a function and call that function then we use the stack frame. • The stack section plays a very important role in the memory because whenever the function is called, a new stack frame is created. • Stack is also used for recursive functions.
  • 12. HEAP • Heap memory is used for the dynamic memory allocation. Heap memory begins from the end of the uninitialized data segment and grows upwards to the higher addresses. • The malloc() and calloc() functions are used to allocate the memory in the heap. • The heap memory can be used by all the shared libraries and dynamically loaded modules. • The free() function is used to deallocate the memory from the heap.
  • 13. EXAMPLE #include<stdio.h> int main() { int *ptr = (int*)malloc(sizeof(int)) ; // memory gets allocated i n the heap segment. return 0; }