Dynamic memory allocation (malloc,calloc,realloc)

In dynamic memory allocation,The required memory size is allocated while program is getting executed. Memory is allocated on demand, under control of the programmer. It exists as long as you need it and is either destroyed sometime after nothing still refers to it – or explicitly when you free it up – depending on the programming language you use.

In dynamic memory allocation,The required memory size is allocated while program is getting executed.

Dynamic memory allocation occurs at runtime, static allocation also but the block of memory is determined by the OS at program start rather than during program run.

. malloc:=>{Allocates the memory of requested size and returns the pointer to the first byte of allocated space.}

2. calloc:=>{Allocates the space for elements of an array. Initializes the elements to zero and returns a pointer to the memory.}

3. realloc:=>{It is used to modify the size of previously allocated memory space.}

4. Free:=>{Frees or empties the previously allocated memory space.}

Use of dynamic memory in c

  • We can dynamically manage memory by creating memory blocks as needed in the heap
  • In dynamic memory allocation, memory is allocated at a run time.
  • Dynamic memory allocation permits to manipulate strings and arrays whose size is flexible and can be changed anytime in your program.
  • It is required when you have no idea how much memory a particular structure is going to occupy.

Hits: 137

Tags: No tags

Share your thoughts