Function name: malloc
Header file : <stdlib.h>
Function prototype : void *malloc(unsigned size);
Function : Used to allocate heap memory of a specified size
Parameter : unsigned size size of allocated space
Return value : Returns a pointer to the allocated memory
Program example : Use this function to dynamically allocate memory for the string www.dotcpp.com.
#include<stdio.h>#include<stdlib.h>#include<string.h>intmain(void){char*p=(char*)malloc(20);strcpy(p,www.dotcpp.com); printf(Stringis%sn,p);free(p);return0;}
Running results
Stringiswww.dotcpp.com