Managing the memory address is called memory management. Almost all computer languages can handle system memory. All the variables used in your program occupy a precise memory space along with the program itself, which needs some memory for storing itself (i.e., its own program).

There are two types of memory allocation 

1. Static memory allocation
2. Dynamic memory allocation

Static memory allocation

In the static memory allocation technique, allocation of memory is done at compilation time, and it stays the same throughout the entire run of your program. Neither any changes will be there in the amount of memory nor any change in the location of memory.

Dynamic memory allocation

In the dynamic memory allocation technique, allocation of memory is done at the time of running the program, and it also has the facility to increase/decrease the memory quantity allocated and can also release or free the memory as and when not required or used. Reallocation of memory can also be done when required. So, it is more advantageous, and memory can be managed efficiently.

Dynamic Memory Allocation in C using 

malloc() 
calloc()
free() 
realloc()

malloc()

The “malloc” or “memory allocation” method in C is used to dynamically allocate a single large block of memory with the specified size.


calloc()

“calloc” or “contiguous allocation” method in C is used to dynamically allocate the specified number of blocks of memory of the specified type. it is very much similar to malloc() but has two different points and these are:

1.It initializes each block with a default value ‘0’
2.It has two parameters or arguments as compare to malloc().


Watch the Video Lecture


            Previous                                                                                                                       Next