what is dynamic memory allocation in c programming? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

what is dynamic memory allocation in c programming?

13th May 2019, 5:45 PM
Sandeep kumar
Sandeep kumar - avatar
2 Answers
+ 3
A simple explanation would be that dynamic memory allocation is done by your program asking the OS for a block of memory and the OS returning the address of the first byte of the memory block (pointer) This block of memory is not managed automatically => Allocation and deallocation have to be performed manually If some memory is not given back (deallocated/freed) and the address of the memory block (handle) is lost, you have a memory leak => No one knows how to access the memory block and no one can deallocate it. The usefulness of dynamic memory allocation comes from the fact that it's only a runtime memory usage: -> It won't increase the size of your executable -> You can allocate only the size you need even if you don't know this information at compile time
13th May 2019, 5:55 PM
Paul