Dma
Dma
1.malloc()
2.calloc()
3.free()
4.realloc()
C malloc() method
• int main()
• {
• // This pointer will hold the
• // base address of the block created
• int* ptr;
• int n, i;
int main()
{
•
int main()
// This pointer will hold the base address of the block created
int n, i;
n = 5;
exit(0);
else {
free(ptr);
free(ptr1);
// Check if the memory has been // Dynamically re-allocate memory using realloc()
successfully ptr = (int*)realloc(ptr, n * sizeof(int));
// allocated by malloc or not
if (ptr == NULL) {
// Memory has been successfully allocated
printf("Memory not allocated.\n");
printf("Memory successfully re-allocated using
exit(0);
realloc.\n");
}
has been
elsesuccessfully
{ allocated
printf("Memory successfully allocated using calloc.\n");
free(ptr);
}
return 0;
}
• Enter number of elements: 5 Memory successfully
allocated using calloc.
• The elements of the array are: 1, 2, 3, 4, 5,
• Enter the new size of the array: 10 Memory
successfully re-allocated using realloc. The
elements of the array are: 1, 2, 3, 4, 5, 6, 7,
8, 9, 10,
Linked List
Struct node {
int data;
struct node * next ;
}
• Displaying the contents of a linked list is very simple.
We keep moving the temp node to the next one and
display its contents.
1. Time Complexity
• Operations Average case time complexity Worst-case time complexity
• Insertion O(1) O(1)
• Deletion O(1) O(1)
• Search O(n) O(n)
Insertion O(n)
Deletion O(n)
Search O(n)