SlideShare a Scribd company logo
1 of 18
Linked LIST
• A linked list is a linear and a non-primitive
data structure in which each element is
allocated dynamically, and each element
points to the next element.
• In other words, we can say that it is a data
structure consisting of a group of nodes that
concurrently represent a sequence.
S.No. ARRAY LINKED LIST
1.
An array is a grouping of data elements of
equivalent data type.
A linked list is a group of entities called a
node. The node includes two segments:
data and address.
2.
It stores the data elements in a
contiguous memory zone.
It stores elements randomly, or we can say
anywhere in the memory zone.
3.
In the case of an array, memory size is
fixed, and it is not possible to change it
during the run time.
In the linked list, the placement of
elements is allocated during the run time.
4.
The elements are not dependent on each
other.
The data elements are dependent on each
other.
5. The memory is assigned at compile time. The memory is assigned at run time.
6.
It is easier and faster to access the
element in an array.
In a linked list, the process of accessing
elements takes more time.
7.
In the case of an array, memory utilization
is ineffective.
In the case of the linked list, memory
utilization is effective.
8
When it comes to executing any operation
like insertion, deletion, array takes more
time.
When it comes to executing any operation
like insertion, deletion, the linked list takes
less time.
Types of Linked Lists:
Simple Linked List
Doubly Linked List
Circular Linked List
Doubly Circular Linked List
Header Linked List
A header linked list is a special type of linked list that contains a header node at
the beginning of the list.
Simple Linked List – In this type of linked list, one can move or traverse the
linked list in only one direction. where the next pointer of each node points to
other nodes but the next pointer of the last node points to NULL. It is also
called “Singly Linked List”.
Doubly Linked List – In this type of linked list, one can move or traverse the
linked list in both directions (Forward and Backward)
Circular Linked List – In this type of linked list, the last node of the linked list
contains the link of the first/head node of the linked list in its next pointer.
Doubly Circular Linked List – A Doubly Circular linked list or a circular two-way
linked list is a more complex type of linked list that contains a pointer to the
next as well as the previous node in the sequence.
. The difference between the doubly linked and circular doubly list is the same as that
between a singly linked list and a circular linked list.
The circular doubly linked list does not contain null in the previous field of the first
node.
• A linked list is a way to store a collection of
elements.
• Each element in a linked list is stored in the
form of a node.
• A node is a collection of two sub-elements or
parts.
– A data part that stores the element
– next part that stores the link to the next node
Declaring a Linked list :
a linked list can be implemented using structure and
pointers .
struct LinkedList
{
int data;
struct LinkedList *next;
};
The above definition is used to create every node in the
list.
– The data field stores the element
– the next is a pointer to store the address of the next node.
struct LinkedList
{
int data;
struct LinkedList *next;
};
In place of a data type, struct LinkedList is written before next.
That's because its a self-referencing pointer. It means a pointer
that points to whatever it is a part of.
Here next is a part of a node and it will point to the next node.
13
MEMORY ALLOCATION PROCESS
The program instructions, global and static variables are stored in a region known as
permanent storage area.
Local variables are stored in another region called stack.
The memory spaced located between stack and permanent storage area is available
for dynamic memory allocation during execution of the program. This free memory region is
called as heap.
14
The memory allocation may be classified as
static memory allocation and dynamic memory
allocation.
Static memory allocation: Memory for the variables
is created at the time of compilation is known as static
memory.
Dynamic memory allocation: Memory for the
variables is allocated at the time of execution of the
program is called dynamic memory.
15
Dynamic memory allocation functions are
defined in stdlib.h and alloc.h header files.
1. malloc()
2. calloc()
3. realloc()
4. free()
malloc(), calloc() and realloc() are memory
allocation functions and free() is a memory releasing
function.
16
1. malloc() function:
malloc() function is used to allocate memory for the
variables at run time.
Syntax: prtvariable = (casttype*)malloc(size);
Where,
ptrvariable is a pointer variable of type casttype.
size represents number of bytes of memory to be
allocated.
17
Example: int *X;
X = (int*)malloc(5*2); (or)
X = (int*)malloc(5*sizeof(int));
Here, malloc() function reserves a single block of
memory with the specified size and returns a pointer of type
void. With this, we can assign it to any type of pointer
variable. By default memory location is filled with garbage
values.
Creating a Node:
typedef is used to define a data type in C.
malloc() is used to dynamically allocate a single block of memory in C, it is
available in the header file stdlib.h.
sizeof() is used to determine size in bytes of an element in C. Here it is
used to determine size of each node and sent as a parameter to malloc.
The above code will create a node with data as value and next pointing to
NULL.

More Related Content

Similar to linked list.pptx

1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 
LINKED LIST.pptx
LINKED LIST.pptxLINKED LIST.pptx
LINKED LIST.pptxDr.Shweta
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testspriyanshukumar97908
 
Data Structures(Part 1)
Data Structures(Part 1)Data Structures(Part 1)
Data Structures(Part 1)SURBHI SAROHA
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfraji175286
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfKamranAli649587
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdfSulabhPawaia
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data StructureJazz Jinia Bhowmik
 
2 Important Data Structure Interview Questions
2 Important Data Structure Interview Questions2 Important Data Structure Interview Questions
2 Important Data Structure Interview QuestionsGeekster
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
DLL DATA STRUCT.pptx
DLL DATA STRUCT.pptxDLL DATA STRUCT.pptx
DLL DATA STRUCT.pptxMuwaffiqa
 
Linear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and QueueLinear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and QueueSelvaraj Seerangan
 

Similar to linked list.pptx (20)

Link list
Link listLink list
Link list
 
Linked List
Linked ListLinked List
Linked List
 
Lecture 2b lists
Lecture 2b listsLecture 2b lists
Lecture 2b lists
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
LINKED LIST.pptx
LINKED LIST.pptxLINKED LIST.pptx
LINKED LIST.pptx
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and tests
 
Data structure
 Data structure Data structure
Data structure
 
Linkedlists
LinkedlistsLinkedlists
Linkedlists
 
Data Structures(Part 1)
Data Structures(Part 1)Data Structures(Part 1)
Data Structures(Part 1)
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
 
Linked list (1).pptx
Linked list (1).pptxLinked list (1).pptx
Linked list (1).pptx
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdf
 
Link list
Link listLink list
Link list
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structure
 
2 Important Data Structure Interview Questions
2 Important Data Structure Interview Questions2 Important Data Structure Interview Questions
2 Important Data Structure Interview Questions
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
DLL DATA STRUCT.pptx
DLL DATA STRUCT.pptxDLL DATA STRUCT.pptx
DLL DATA STRUCT.pptx
 
Linear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and QueueLinear Data Structures - List, Stack and Queue
Linear Data Structures - List, Stack and Queue
 
unit 1.pptx
unit 1.pptxunit 1.pptx
unit 1.pptx
 

Recently uploaded

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...chiefasafspells
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 

Recently uploaded (20)

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 

linked list.pptx

  • 1. Linked LIST • A linked list is a linear and a non-primitive data structure in which each element is allocated dynamically, and each element points to the next element. • In other words, we can say that it is a data structure consisting of a group of nodes that concurrently represent a sequence.
  • 2.
  • 3. S.No. ARRAY LINKED LIST 1. An array is a grouping of data elements of equivalent data type. A linked list is a group of entities called a node. The node includes two segments: data and address. 2. It stores the data elements in a contiguous memory zone. It stores elements randomly, or we can say anywhere in the memory zone. 3. In the case of an array, memory size is fixed, and it is not possible to change it during the run time. In the linked list, the placement of elements is allocated during the run time. 4. The elements are not dependent on each other. The data elements are dependent on each other. 5. The memory is assigned at compile time. The memory is assigned at run time. 6. It is easier and faster to access the element in an array. In a linked list, the process of accessing elements takes more time. 7. In the case of an array, memory utilization is ineffective. In the case of the linked list, memory utilization is effective. 8 When it comes to executing any operation like insertion, deletion, array takes more time. When it comes to executing any operation like insertion, deletion, the linked list takes less time.
  • 4. Types of Linked Lists: Simple Linked List Doubly Linked List Circular Linked List Doubly Circular Linked List Header Linked List A header linked list is a special type of linked list that contains a header node at the beginning of the list.
  • 5. Simple Linked List – In this type of linked list, one can move or traverse the linked list in only one direction. where the next pointer of each node points to other nodes but the next pointer of the last node points to NULL. It is also called “Singly Linked List”.
  • 6. Doubly Linked List – In this type of linked list, one can move or traverse the linked list in both directions (Forward and Backward)
  • 7. Circular Linked List – In this type of linked list, the last node of the linked list contains the link of the first/head node of the linked list in its next pointer.
  • 8. Doubly Circular Linked List – A Doubly Circular linked list or a circular two-way linked list is a more complex type of linked list that contains a pointer to the next as well as the previous node in the sequence. . The difference between the doubly linked and circular doubly list is the same as that between a singly linked list and a circular linked list. The circular doubly linked list does not contain null in the previous field of the first node.
  • 9. • A linked list is a way to store a collection of elements. • Each element in a linked list is stored in the form of a node. • A node is a collection of two sub-elements or parts. – A data part that stores the element – next part that stores the link to the next node
  • 10.
  • 11. Declaring a Linked list : a linked list can be implemented using structure and pointers . struct LinkedList { int data; struct LinkedList *next; }; The above definition is used to create every node in the list. – The data field stores the element – the next is a pointer to store the address of the next node.
  • 12. struct LinkedList { int data; struct LinkedList *next; }; In place of a data type, struct LinkedList is written before next. That's because its a self-referencing pointer. It means a pointer that points to whatever it is a part of. Here next is a part of a node and it will point to the next node.
  • 13. 13 MEMORY ALLOCATION PROCESS The program instructions, global and static variables are stored in a region known as permanent storage area. Local variables are stored in another region called stack. The memory spaced located between stack and permanent storage area is available for dynamic memory allocation during execution of the program. This free memory region is called as heap.
  • 14. 14 The memory allocation may be classified as static memory allocation and dynamic memory allocation. Static memory allocation: Memory for the variables is created at the time of compilation is known as static memory. Dynamic memory allocation: Memory for the variables is allocated at the time of execution of the program is called dynamic memory.
  • 15. 15 Dynamic memory allocation functions are defined in stdlib.h and alloc.h header files. 1. malloc() 2. calloc() 3. realloc() 4. free() malloc(), calloc() and realloc() are memory allocation functions and free() is a memory releasing function.
  • 16. 16 1. malloc() function: malloc() function is used to allocate memory for the variables at run time. Syntax: prtvariable = (casttype*)malloc(size); Where, ptrvariable is a pointer variable of type casttype. size represents number of bytes of memory to be allocated.
  • 17. 17 Example: int *X; X = (int*)malloc(5*2); (or) X = (int*)malloc(5*sizeof(int)); Here, malloc() function reserves a single block of memory with the specified size and returns a pointer of type void. With this, we can assign it to any type of pointer variable. By default memory location is filled with garbage values.
  • 18. Creating a Node: typedef is used to define a data type in C. malloc() is used to dynamically allocate a single block of memory in C, it is available in the header file stdlib.h. sizeof() is used to determine size in bytes of an element in C. Here it is used to determine size of each node and sent as a parameter to malloc. The above code will create a node with data as value and next pointing to NULL.