SlideShare une entreprise Scribd logo
1  sur  8
Dynamic Memory Allocation and
Linked Lists
Topics
 Dynamic memory allocation

Dynamic Memory Allocation
 The process of allocating memory at run
time is known as dynamic memory
allocation.
 There are some functions for dynamic
memory allocation. These are malloc, calloc,
free and realloc.
Allocating a Block of Memory
 A block of memory may be allocated using
the function malloc. The malloc function
reserves a block of memory of specified size
and returns a pointer of type void. The form-
ptr = (cast-type *)malloc(byte-size);
ptr is a pointer of type cast-type.
 Example:
ptr = (int *) malloc(100*sizeof(int));
Allocating Multiple blocks of Memory
 Calloc is another memory allocation function
that is normally used for request memory
space at run time for storing derived data
types such as array and structures. It
allocates multiple blocks of storage, each of
the same size. The general format-
ptr = (cast-type *)calloc(n,element-size);
Releasing the used space & Altering the size
 free function can be used to release the
used space. The format is-
free(ptr);
 We can change the memory size already
allocated with the help of the function
realloc.
ptr = realloc(ptr, newsize);
Concepts of Linked List
 A linked list is one kind of list whose order is given
by links from one item to the next.
 Each structure of the list is called a node and
consists of two fields, one containing the item and
the other containing the address of the next item in
the list.
 A linked list is therefore a collection of structures
ordered not by their physical placement in memory
but by logical links that are stored as part of the
data in the structure itself. The link is in the form of
a pointer to another structure of the same type.
Continue…
 The structure is represented as:
struct node
{
int item;
struct node *next;
};
Advantage of Linked List
 Advantages:
1. Linked list can grow or shrink in size
during the execution of a program.
2. It does not waste memory space.
3. It provides flexibility in allowing the items
to be rearranged efficiently.
 Limitation:
1. The access of any arbitrary item is little
cumbersome and time consuming.
2. It will use more storage than an array with
the same number of items as it has link field.

Contenu connexe

Tendances

Union in C programming
Union in C programmingUnion in C programming
Union in C programmingKamal Acharya
 
1. Data structures introduction
1. Data structures introduction1. Data structures introduction
1. Data structures introductionMandeep Singh
 
Union In language C
Union In language CUnion In language C
Union In language CRavi Singh
 
Str
StrStr
StrAcad
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structureshaibal sharif
 
Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation ashu awais
 
Basics of data structure
Basics of data structureBasics of data structure
Basics of data structureRajendran
 
Over view of data structures
Over view of data structuresOver view of data structures
Over view of data structuresNagajothiN1
 
Union in c language
Union  in c languageUnion  in c language
Union in c languagetanmaymodi4
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structuresunilchute1
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture topu93
 

Tendances (17)

Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Structure in c
Structure in cStructure in c
Structure in c
 
1. Data structures introduction
1. Data structures introduction1. Data structures introduction
1. Data structures introduction
 
Union In language C
Union In language CUnion In language C
Union In language C
 
Str
StrStr
Str
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Week 4 dq 4
Week 4 dq 4Week 4 dq 4
Week 4 dq 4
 
Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation
 
Basics of data structure
Basics of data structureBasics of data structure
Basics of data structure
 
Over view of data structures
Over view of data structuresOver view of data structures
Over view of data structures
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 
Data structures
Data structuresData structures
Data structures
 
Data strucer
Data strucerData strucer
Data strucer
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
Data struters
Data strutersData struters
Data struters
 
Data structure
Data  structureData  structure
Data structure
 

En vedette

04 ds and algorithm session_05
04 ds and algorithm session_0504 ds and algorithm session_05
04 ds and algorithm session_05Niit Care
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi Kv
 
07 ds and algorithm session_10
07 ds and algorithm session_1007 ds and algorithm session_10
07 ds and algorithm session_10Niit Care
 
05 ds and algorithm session_07
05 ds and algorithm session_0705 ds and algorithm session_07
05 ds and algorithm session_07Niit Care
 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structuresWipro
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsMultiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsDr Sandeep Kumar Poonia
 
Sparse matrices
Sparse matricesSparse matrices
Sparse matricesZain Zafar
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Adam Mukharil Bachtiar
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Top10 Innovative Ideas You Haven't Heard of in the Developing World
Top10 Innovative Ideas You Haven't Heard of in the Developing WorldTop10 Innovative Ideas You Haven't Heard of in the Developing World
Top10 Innovative Ideas You Haven't Heard of in the Developing WorldMahindra Rise
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 

En vedette (20)

Linked list
Linked listLinked list
Linked list
 
04 ds and algorithm session_05
04 ds and algorithm session_0504 ds and algorithm session_05
04 ds and algorithm session_05
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
07 ds and algorithm session_10
07 ds and algorithm session_1007 ds and algorithm session_10
07 ds and algorithm session_10
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Lec6 mod linked list
Lec6 mod linked listLec6 mod linked list
Lec6 mod linked list
 
05 ds and algorithm session_07
05 ds and algorithm session_0705 ds and algorithm session_07
05 ds and algorithm session_07
 
Linked Lists
Linked ListsLinked Lists
Linked Lists
 
Applications of data structures
Applications of data structuresApplications of data structures
Applications of data structures
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsMultiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
 
Sparse matrices
Sparse matricesSparse matrices
Sparse matrices
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
 
linked list
linked list linked list
linked list
 
Linked list
Linked listLinked list
Linked list
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Top10 Innovative Ideas You Haven't Heard of in the Developing World
Top10 Innovative Ideas You Haven't Heard of in the Developing WorldTop10 Innovative Ideas You Haven't Heard of in the Developing World
Top10 Innovative Ideas You Haven't Heard of in the Developing World
 
Data Structure
Data StructureData Structure
Data Structure
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 

Similaire à Chap 13(dynamic memory allocation)

DS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptxDS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptxprakashvs7
 
Data Structures_Introduction
Data Structures_IntroductionData Structures_Introduction
Data Structures_IntroductionThenmozhiK5
 
Data and File Structure Lecture Notes
Data and File Structure Lecture NotesData and File Structure Lecture Notes
Data and File Structure Lecture NotesFellowBuddy.com
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptxjack881
 
Dma
DmaDma
DmaAcad
 
Data Structure & Algorithm.pptx
Data Structure & Algorithm.pptxData Structure & Algorithm.pptx
Data Structure & Algorithm.pptxMumtaz
 
Chapter 1 - Introduction to Data Structure.ppt
Chapter 1 - Introduction to Data Structure.pptChapter 1 - Introduction to Data Structure.ppt
Chapter 1 - Introduction to Data Structure.pptNORSHADILAAHMADBADEL
 
Data Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxData Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxGIRISHKUMARBC1
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programmingTOPS Technologies
 
Collectn framework copy
Collectn framework   copyCollectn framework   copy
Collectn framework copycharan kumar
 
Collectn framework
Collectn frameworkCollectn framework
Collectn frameworkcharan kumar
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocationMoniruzzaman _
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++Jeff TUYISHIME
 

Similaire à Chap 13(dynamic memory allocation) (20)

DS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptxDS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptx
 
Data Structures_Introduction
Data Structures_IntroductionData Structures_Introduction
Data Structures_Introduction
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
Data and File Structure Lecture Notes
Data and File Structure Lecture NotesData and File Structure Lecture Notes
Data and File Structure Lecture Notes
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptx
 
Dma
DmaDma
Dma
 
Data Structure & Algorithm.pptx
Data Structure & Algorithm.pptxData Structure & Algorithm.pptx
Data Structure & Algorithm.pptx
 
Chapter 1 - Introduction to Data Structure.ppt
Chapter 1 - Introduction to Data Structure.pptChapter 1 - Introduction to Data Structure.ppt
Chapter 1 - Introduction to Data Structure.ppt
 
Data Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxData Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptx
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
06 linked list
06 linked list06 linked list
06 linked list
 
Collectn framework copy
Collectn framework   copyCollectn framework   copy
Collectn framework copy
 
Collectn framework
Collectn frameworkCollectn framework
Collectn framework
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Mca 504 dotnet_unit3
Mca 504 dotnet_unit3Mca 504 dotnet_unit3
Mca 504 dotnet_unit3
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
 
Linked list
Linked listLinked list
Linked list
 
Data structures
Data structuresData structures
Data structures
 

Plus de Bangabandhu Sheikh Mujibur Rahman Science and Technology University

Plus de Bangabandhu Sheikh Mujibur Rahman Science and Technology University (20)

Antenna (2)
Antenna (2)Antenna (2)
Antenna (2)
 
Voltage suppler..
Voltage suppler..Voltage suppler..
Voltage suppler..
 
Number system
Number systemNumber system
Number system
 
Chap 12(files)
Chap 12(files)Chap 12(files)
Chap 12(files)
 
Chap 11(pointers)
Chap 11(pointers)Chap 11(pointers)
Chap 11(pointers)
 
Chap 10(structure and unions)
Chap 10(structure and unions)Chap 10(structure and unions)
Chap 10(structure and unions)
 
Chap 9(functions)
Chap 9(functions)Chap 9(functions)
Chap 9(functions)
 
Chap 8(strings)
Chap 8(strings)Chap 8(strings)
Chap 8(strings)
 
Chap 7(array)
Chap 7(array)Chap 7(array)
Chap 7(array)
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
 
Chap 5(decision making-branching)
Chap 5(decision making-branching)Chap 5(decision making-branching)
Chap 5(decision making-branching)
 
Chap 3(operator expression)
Chap 3(operator expression)Chap 3(operator expression)
Chap 3(operator expression)
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
Computer hardware ppt1
Computer hardware ppt1Computer hardware ppt1
Computer hardware ppt1
 
# Operating system
# Operating system# Operating system
# Operating system
 
Magnetism 3
Magnetism 3Magnetism 3
Magnetism 3
 
Magnetism 2
Magnetism 2Magnetism 2
Magnetism 2
 
2. sinusoidal waves
2. sinusoidal waves2. sinusoidal waves
2. sinusoidal waves
 
Magnetism 1
Magnetism 1Magnetism 1
Magnetism 1
 
1. rc rl-rlc
1. rc rl-rlc1. rc rl-rlc
1. rc rl-rlc
 

Dernier

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Dernier (20)

fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

Chap 13(dynamic memory allocation)

  • 1. Dynamic Memory Allocation and Linked Lists Topics  Dynamic memory allocation 
  • 2. Dynamic Memory Allocation  The process of allocating memory at run time is known as dynamic memory allocation.  There are some functions for dynamic memory allocation. These are malloc, calloc, free and realloc.
  • 3. Allocating a Block of Memory  A block of memory may be allocated using the function malloc. The malloc function reserves a block of memory of specified size and returns a pointer of type void. The form- ptr = (cast-type *)malloc(byte-size); ptr is a pointer of type cast-type.  Example: ptr = (int *) malloc(100*sizeof(int));
  • 4. Allocating Multiple blocks of Memory  Calloc is another memory allocation function that is normally used for request memory space at run time for storing derived data types such as array and structures. It allocates multiple blocks of storage, each of the same size. The general format- ptr = (cast-type *)calloc(n,element-size);
  • 5. Releasing the used space & Altering the size  free function can be used to release the used space. The format is- free(ptr);  We can change the memory size already allocated with the help of the function realloc. ptr = realloc(ptr, newsize);
  • 6. Concepts of Linked List  A linked list is one kind of list whose order is given by links from one item to the next.  Each structure of the list is called a node and consists of two fields, one containing the item and the other containing the address of the next item in the list.  A linked list is therefore a collection of structures ordered not by their physical placement in memory but by logical links that are stored as part of the data in the structure itself. The link is in the form of a pointer to another structure of the same type.
  • 7. Continue…  The structure is represented as: struct node { int item; struct node *next; };
  • 8. Advantage of Linked List  Advantages: 1. Linked list can grow or shrink in size during the execution of a program. 2. It does not waste memory space. 3. It provides flexibility in allowing the items to be rearranged efficiently.  Limitation: 1. The access of any arbitrary item is little cumbersome and time consuming. 2. It will use more storage than an array with the same number of items as it has link field.