The malloc()  function dynamically allocates memory when required. This function allocates ‘size’ byte of memory and returns a pointer to the first byte or NULL if there is some kind of error.span>

Format is as follows. 
void * malloc (size_t size);



pointer = (type) malloc (size in bytes);

An example:


int * p;
p = (int *) malloc (sizeof (int));
* p = 5;


 The calloc() function is used to allocate storage to a variable while the program is running. This library function is invoked by writing calloc(num,size).

Format is as follows.

void * calloc (size_t n, size_t size);


For example, an int array of 10 elements can be allocated as follows.

int * array = (int *) calloc (10, sizeof (int));
Note that this function can also malloc, written as follows.
int * array = (int *) malloc (sizeof (int) * 10);