SlideShare uma empresa Scribd logo
1 de 16
Prepared By:
Savani Nirali
Sanghani Monika
Patel Pooja
How and Where C datatypes are
stored in Memory
C Data types:
 Basic Types:
They are arithmetic types and consists of the two
types: (a) integer types and (b) floating-point types.
 Enumerated types:
They are again arithmetic types and they are
used to define variables that can only be assigned
certain discrete integer values throughout the
program.
 The type void:
The type specifier void indicates that no value is
available.
 Derived types:
They include (a) Pointer types, (b) Array types,
(c) Structure types, (d) Union types and (e) Function
Integer Types:
Type Storage size Value range
Char 1 byte -128 to 127 or 0 to 255
Unsigned Char 1 byte 0 to 255
Signed Char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or
-2,147,483,648 to 2,147,483,647
Unsigned int 2 or 4 bytes 0 to 65,535 or
0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
Unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
Unsigned long 4 bytes 0 to 4,294,967,295
 Memory representation of char data type in C
Char data types may be signed or unsigned. Size of char data
type is 8 bit. Both signed and unsigned have different memory
representation.
Memory representation of unsigned char: In unsigned char all 8 bit
is used as data bit
Memory representation of unsigned char a= 7;
Binary equivalent of 7 is: 111
For 8 bit we will add 5 zero in the left side i.e. 00000111. In the
memory:
 Here MSD stand for most significant digit and LSD list significant
digit.
 Memory representation of signed char:
1 bit: signed bit
7 bit: data bit
Note: In C, negative number is stored in the 2’s complement format.
Signed bit is 0: Number is positive.
Signed bit is 1: Number is negative.
Memory representation of char a=7;
Binary equivalent of 7 is: 111
For 8 bit we will add 5 zero in the left side i.e. 00000111. Memory
representation:
 Memory representation of char a=-7;
Binary equivalent of 7 is 111
For 8 bit we will add 5 zero in the left side i.e. 00000111. Since a
is negative number so it will store in the memory in the 2’s
complement format
 1’s complement of a: 11111000
+ 1
____________
 2’s complement of a: 11111001
Memory representation:
Floating Point Types:
Type Storage value Value range Precision
Float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte
2.3E-308 to 1.7E+308
15 decimal places
Long double 10-byte 3.4E-4932 to 1.1E+4932 19 decimal places
 To get the exact size of a type or a variable on a particular platform, you can use the
sizeof operator. The expressions sizeof(type) yields the storage size of the object or type
in bytes. Following is an example:
#include <stdio.h>
#include <conio.h>
#include <float.h>
int main(){
printf("Storage size for int : %d n", sizeof(int));
printf("Storage size for float : %d n", sizeof(float));
printf("Minimum float positive value: %En", FLT_MIN );
printf("Maximum float positive value: %En", FLT_MAX );
return 0;
}
When you compile and execute the above program it produces the following
result on Linux:
Storage size for int : 4
Storage size for float : 4
Minimum float positive value: 1.175494E-38
Maximum float positive value: 3.402823E+38
The Void Type:
Serial
Number
:
Types and Description
1 Function returns as void :
There are various functions in C which do not return value or
you can say they return void. A function with no return value has
the return type as void. For example void exit (int status);
2 Function arguments as void
There are various functions in C which do not accept any
parameter. A function with no parameter can accept as a void.
For example, int rand(void);
3 Pointers to void
A pointer of type void * represents the address of an object, but
not its type. For example a memory allocation function void
*malloc( size_t size ); returns a pointer to void which can be
casted to any data type.
Enum [Enumerated] data types:
 Syntax:
enum identifier {value1, value2,.... Value n};
 enum is ” Enumerated Data Type “.
 enum is user defined data type
 In the above example “identifier” is nothing but the user defined data
type .
 Value1,Value2,Value3….. etc creates one set of enum values.
 Using “identifier” we are creating our variables.
Memory Layout
 Text or Code Segment
Code segment, also known as text segment contains
machine code of the compiled program. The text segment of an
executable object file is often read-only segment that prevents a
program from being accidentally modified.
 Data Segments
Data segment stores program data. This data could be in
form of initialized or uninitialized variables, and it could be local
or global.
Data segment is further divided into four sub-data
segments (initialized data segment, uninitialized or .bss data
segment, stack, and heap) to store variables depending upon if
they are local or global, and initialized or uninitialized.
Memory Layout (Cont.)
 Initialized Data or Data Segment
Initialized data or simply data segment stores all global,
static, constant, and external variables (declared
with extern keyword) that are initialized beforehand.
 Uninitialized Data or .bss Segment
Contrary to initialized data segment, uninitialized
data or .bss segment stores all uninitialized global, static, and
external variables (declared with extern keyword). Global,
external, and static variable are by default initialized to zero.
Object file formats distinguish between initialized and
uninitialized variables for space efficiency; uninitialized
variables do not have to occupy any actual disk space in the
object file.
Memory Layout (Cont.)
Figure 1 : Memory Layout of C Program
Memory Layout (Cont.)
 Stack Segment
Stack segment is used to store all local variables and is
used for passing arguments to the functions along with the return
address of the instruction which is to be executed after the
function call is over. Local pointers are stored in stack segment.
 Heap Segment
Heap segment is also part of RAM where dynamically
allocated variables are stored. In C language dynamic memory
allocation is done by using malloc and calloc functions. Global
pointers are automatically stored in Heap segment.
When some more memory need to be allocated
using malloc and calloc function, heap grows upward as shown
in Figure 1.
Big and Little Endian
 Big Endian : In big endian, you store the most significant byte
in the smallest address.
 Little Endian : In little endian, you store the least significant
byte in the smallest address.
THANK YOU

Mais conteúdo relacionado

Mais procurados (20)

Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
Java applet - java
Java applet - javaJava applet - java
Java applet - java
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 
Event handling
Event handlingEvent handling
Event handling
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Python Generators
Python GeneratorsPython Generators
Python Generators
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOC
 
Applets in java
Applets in javaApplets in java
Applets in java
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
20. Parallel Databases in DBMS
20. Parallel Databases in DBMS20. Parallel Databases in DBMS
20. Parallel Databases in DBMS
 
Curves and Surfaces
Curves and SurfacesCurves and Surfaces
Curves and Surfaces
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 

Destaque

C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 SlidesRakesh Roshan
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageRakesh Roshan
 
Mechanics of materials
Mechanics of materialsMechanics of materials
Mechanics of materialsSelf-employed
 
differential equations Boyce & Diprima Solution manual
differential equations Boyce & Diprima Solution manualdifferential equations Boyce & Diprima Solution manual
differential equations Boyce & Diprima Solution manualshayangreen
 
2 axial loading- Mechanics of Materials - 4th - Beer
2 axial loading- Mechanics of Materials - 4th - Beer2 axial loading- Mechanics of Materials - 4th - Beer
2 axial loading- Mechanics of Materials - 4th - BeerNhan Tran
 
3 torsion- Mechanics of Materials - 4th - Beer
3 torsion- Mechanics of Materials - 4th - Beer3 torsion- Mechanics of Materials - 4th - Beer
3 torsion- Mechanics of Materials - 4th - BeerNhan Tran
 
Higher Differential Equation
Higher Differential EquationHigher Differential Equation
Higher Differential Equationgtuautonomous
 
02 first order differential equations
02 first order differential equations02 first order differential equations
02 first order differential equationsvansi007
 
Mechanics of materials lecture 01, Engr. Abdullah Khan
Mechanics of materials lecture 01, Engr. Abdullah KhanMechanics of materials lecture 01, Engr. Abdullah Khan
Mechanics of materials lecture 01, Engr. Abdullah KhanAbdullah Khan
 
Higher Differential Equation
Higher Differential Equation Higher Differential Equation
Higher Differential Equation Abdul Hannan
 

Destaque (13)

Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
Mechanics of materials
Mechanics of materialsMechanics of materials
Mechanics of materials
 
differential equations Boyce & Diprima Solution manual
differential equations Boyce & Diprima Solution manualdifferential equations Boyce & Diprima Solution manual
differential equations Boyce & Diprima Solution manual
 
Higher order differential equations
Higher order differential equationsHigher order differential equations
Higher order differential equations
 
Unit 2 stresses in composite sections
Unit 2  stresses in composite sectionsUnit 2  stresses in composite sections
Unit 2 stresses in composite sections
 
2 axial loading- Mechanics of Materials - 4th - Beer
2 axial loading- Mechanics of Materials - 4th - Beer2 axial loading- Mechanics of Materials - 4th - Beer
2 axial loading- Mechanics of Materials - 4th - Beer
 
3 torsion- Mechanics of Materials - 4th - Beer
3 torsion- Mechanics of Materials - 4th - Beer3 torsion- Mechanics of Materials - 4th - Beer
3 torsion- Mechanics of Materials - 4th - Beer
 
Higher Differential Equation
Higher Differential EquationHigher Differential Equation
Higher Differential Equation
 
02 first order differential equations
02 first order differential equations02 first order differential equations
02 first order differential equations
 
Mechanics of materials lecture 01, Engr. Abdullah Khan
Mechanics of materials lecture 01, Engr. Abdullah KhanMechanics of materials lecture 01, Engr. Abdullah Khan
Mechanics of materials lecture 01, Engr. Abdullah Khan
 
Higher Differential Equation
Higher Differential Equation Higher Differential Equation
Higher Differential Equation
 

Semelhante a Memory management of datatypes

datatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptxdatatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptxNaniBhai3
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6REHAN IJAZ
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
Unit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.pptUnit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.pptpubgnewstate1620
 
C Sharp Nagina (1)
C Sharp Nagina (1)C Sharp Nagina (1)
C Sharp Nagina (1)guest58c84c
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)jahanullah
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorialMohit Saini
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introductionnikshaikh786
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction toolssunilchute1
 
Data Reprersentation
Data Reprersentation  Data Reprersentation
Data Reprersentation Kamal Acharya
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.pptAqeelAbbas94
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C ProgrammingQazi Shahzad Ali
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersTanishq Soni
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++Neeru Mittal
 

Semelhante a Memory management of datatypes (20)

datatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptxdatatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptx
 
PSPC--UNIT-2.pdf
PSPC--UNIT-2.pdfPSPC--UNIT-2.pdf
PSPC--UNIT-2.pdf
 
Programming Fundamentals lecture 6
Programming Fundamentals lecture 6Programming Fundamentals lecture 6
Programming Fundamentals lecture 6
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
Theory1&amp;2
Theory1&amp;2Theory1&amp;2
Theory1&amp;2
 
Unit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.pptUnit 1 Built in Data types in C language.ppt
Unit 1 Built in Data types in C language.ppt
 
C Sharp Nagina (1)
C Sharp Nagina (1)C Sharp Nagina (1)
C Sharp Nagina (1)
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
 
Data Reprersentation
Data Reprersentation  Data Reprersentation
Data Reprersentation
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt
 
Data Type in C Programming
Data Type in C ProgrammingData Type in C Programming
Data Type in C Programming
 
Literals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiersLiterals, primitive datatypes, variables, expressions, identifiers
Literals, primitive datatypes, variables, expressions, identifiers
 
5 introduction-to-c
5 introduction-to-c5 introduction-to-c
5 introduction-to-c
 
datareprersentation 1.pptx
datareprersentation 1.pptxdatareprersentation 1.pptx
datareprersentation 1.pptx
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 

Último

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 

Último (20)

Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 

Memory management of datatypes

  • 1. Prepared By: Savani Nirali Sanghani Monika Patel Pooja How and Where C datatypes are stored in Memory
  • 2. C Data types:  Basic Types: They are arithmetic types and consists of the two types: (a) integer types and (b) floating-point types.  Enumerated types: They are again arithmetic types and they are used to define variables that can only be assigned certain discrete integer values throughout the program.  The type void: The type specifier void indicates that no value is available.  Derived types: They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function
  • 3. Integer Types: Type Storage size Value range Char 1 byte -128 to 127 or 0 to 255 Unsigned Char 1 byte 0 to 255 Signed Char 1 byte -128 to 127 int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 Unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295 short 2 bytes -32,768 to 32,767 Unsigned short 2 bytes 0 to 65,535 long 4 bytes -2,147,483,648 to 2,147,483,647 Unsigned long 4 bytes 0 to 4,294,967,295
  • 4.  Memory representation of char data type in C Char data types may be signed or unsigned. Size of char data type is 8 bit. Both signed and unsigned have different memory representation. Memory representation of unsigned char: In unsigned char all 8 bit is used as data bit Memory representation of unsigned char a= 7; Binary equivalent of 7 is: 111 For 8 bit we will add 5 zero in the left side i.e. 00000111. In the memory:  Here MSD stand for most significant digit and LSD list significant digit.
  • 5.  Memory representation of signed char: 1 bit: signed bit 7 bit: data bit Note: In C, negative number is stored in the 2’s complement format. Signed bit is 0: Number is positive. Signed bit is 1: Number is negative. Memory representation of char a=7; Binary equivalent of 7 is: 111 For 8 bit we will add 5 zero in the left side i.e. 00000111. Memory representation:
  • 6.  Memory representation of char a=-7; Binary equivalent of 7 is 111 For 8 bit we will add 5 zero in the left side i.e. 00000111. Since a is negative number so it will store in the memory in the 2’s complement format  1’s complement of a: 11111000 + 1 ____________  2’s complement of a: 11111001 Memory representation:
  • 7. Floating Point Types: Type Storage value Value range Precision Float 4 byte 1.2E-38 to 3.4E+38 6 decimal places double 8 byte 2.3E-308 to 1.7E+308 15 decimal places Long double 10-byte 3.4E-4932 to 1.1E+4932 19 decimal places
  • 8.  To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes. Following is an example: #include <stdio.h> #include <conio.h> #include <float.h> int main(){ printf("Storage size for int : %d n", sizeof(int)); printf("Storage size for float : %d n", sizeof(float)); printf("Minimum float positive value: %En", FLT_MIN ); printf("Maximum float positive value: %En", FLT_MAX ); return 0; } When you compile and execute the above program it produces the following result on Linux: Storage size for int : 4 Storage size for float : 4 Minimum float positive value: 1.175494E-38 Maximum float positive value: 3.402823E+38
  • 9. The Void Type: Serial Number : Types and Description 1 Function returns as void : There are various functions in C which do not return value or you can say they return void. A function with no return value has the return type as void. For example void exit (int status); 2 Function arguments as void There are various functions in C which do not accept any parameter. A function with no parameter can accept as a void. For example, int rand(void); 3 Pointers to void A pointer of type void * represents the address of an object, but not its type. For example a memory allocation function void *malloc( size_t size ); returns a pointer to void which can be casted to any data type.
  • 10. Enum [Enumerated] data types:  Syntax: enum identifier {value1, value2,.... Value n};  enum is ” Enumerated Data Type “.  enum is user defined data type  In the above example “identifier” is nothing but the user defined data type .  Value1,Value2,Value3….. etc creates one set of enum values.  Using “identifier” we are creating our variables.
  • 11. Memory Layout  Text or Code Segment Code segment, also known as text segment contains machine code of the compiled program. The text segment of an executable object file is often read-only segment that prevents a program from being accidentally modified.  Data Segments Data segment stores program data. This data could be in form of initialized or uninitialized variables, and it could be local or global. Data segment is further divided into four sub-data segments (initialized data segment, uninitialized or .bss data segment, stack, and heap) to store variables depending upon if they are local or global, and initialized or uninitialized.
  • 12. Memory Layout (Cont.)  Initialized Data or Data Segment Initialized data or simply data segment stores all global, static, constant, and external variables (declared with extern keyword) that are initialized beforehand.  Uninitialized Data or .bss Segment Contrary to initialized data segment, uninitialized data or .bss segment stores all uninitialized global, static, and external variables (declared with extern keyword). Global, external, and static variable are by default initialized to zero. Object file formats distinguish between initialized and uninitialized variables for space efficiency; uninitialized variables do not have to occupy any actual disk space in the object file.
  • 13. Memory Layout (Cont.) Figure 1 : Memory Layout of C Program
  • 14. Memory Layout (Cont.)  Stack Segment Stack segment is used to store all local variables and is used for passing arguments to the functions along with the return address of the instruction which is to be executed after the function call is over. Local pointers are stored in stack segment.  Heap Segment Heap segment is also part of RAM where dynamically allocated variables are stored. In C language dynamic memory allocation is done by using malloc and calloc functions. Global pointers are automatically stored in Heap segment. When some more memory need to be allocated using malloc and calloc function, heap grows upward as shown in Figure 1.
  • 15. Big and Little Endian  Big Endian : In big endian, you store the most significant byte in the smallest address.  Little Endian : In little endian, you store the least significant byte in the smallest address.