The process of allocating memory at runtime is known as Dynamic Memory Allocation. Dynamic memory management techniques permit us to allocate additional memory space or to release unwanted space at runtime. Linked List is one of the basic types of dynamic data structures. It provides flexibility in adding, deleting or rearranging data items at runtime. Dynamic memory management technique uses the memory management functions, which are used for allocating and freeing memory during program execution.
malloc:- It allocates required size of bytes and returns a pointer to the first byte of allocated space.
Pointer_variable=(type casting) malloc (n*sizeof(datatype));
Where n is the no.of elements
The return type of malloc & calloc is void. Hence typecasting is needed.
malloc allocates memory but it doesnot initialize the memory location.
calloc -> allocates space for an array of elements initializes them to zero and then returns a pointer to the memory.
free-> free previously allocated space.
Ex:- free(pointer_variable);
realloc -> modifies the size of previously allocated space.
No comments:
Post a Comment