Type casting and malloc( )

Learn the functionality of malloc( ) with an interactive example.

What is malloc( )?


malloc( ) is a library function that is used for dynamic memory allocation.


In dynamic memory allocation, we are required to look at both decisions—how much memory to allocate and where to allocate—during execution.

The number of bytes that should be allocated is passed to malloc( ) as an argument. malloc( ) allocates a specified amount of memory and returns the base address of the memory chunk allocated as a void pointer.

Example program

See the code given below!

Get hands-on with 1400+ tech skills courses.