Write a C Program for dynamic memory allocation using malloc( )

By | March 19, 2017

C Program to understand dynamic memory allocation


Write a C Program to understand dynamic memory allocation using malloc( ). Here’s a Simple Program to understand dynamic memory allocation using malloc( ) in C Programming Language.


DYNAMIC MEMORY ALLOCATION :


The process of allocating memory during program execution is called dynamic memory allocation.

Library routines known as “memory management functions” are used for allocating and freeing memory during execution of a program. These functions are defined in stdlib.h.


 MALLOC() FUNCTION IN C:


  • malloc () function is used to allocate space in memory during the execution of the program.
  • malloc () does not initialize the memory allocated during execution.  It carries garbage value.
  • malloc () function returns null pointer if it couldn’t able to allocate requested amount of memory.

 

Syntax of malloc( ) function :


 ptr = (cast-type *)malloc(byte-size) ;

Below is the source code for C Program to understand dynamic memory allocation using malloc( ) which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :



OUTPUT : :



If you found any error or any queries related to the above program or any questions , doubts or reviews , you wanna to ask or share to us, you may Contact Us  through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in the short interval of time.


Thanks for reading the post.

Leave a Reply