malloc()

Some one please explain me what is Dynamic memory allocation and the use of malloc() function.How do we allocate memory dynamically and also the other way?

Google for "dynamic memory allocation".

Regards

Allocating memory for a variable in run-time called Dynamic Memory allocation.

Suppose in certain condition, if you would like to allocate some memory based on a value of an variable then we have to go for the Dynamic Memory allocation.

Simply saying, you can allocate in compile time if you know the exact size for a variable, if not you can allocate in runtime based on a runtime value.

There are two other ways:

  • Globally (static arrays declared outside of a function)
  • Locally (declared on the "stack")

There are also ways to allocate "shared memory", which is dynamically memory that other processes can use. There are also a few other, highly nuanced types.