Function name : realloc
Header file : <stdlib.h>
Function prototype : void *realloc(void *p,unsigned size);
Function : Used to reallocate heap memory space of a specified size
Parameters : void *p pointer to memory area
unsigned size is the size of reallocated memory
Return value : Returns the pointer to the memory block after reallocation
Program example : Use this function to allocate memory for d
#include<stdio.h>#include<stdlib.h>intmain(void){double*d=(double*)malloc(sizeof(double));*d=3.14;printf (thevalueis%lfn,*d);int*i=(int*)realloc(d,sizeof(int));*i=90;printf(thevalueis%dn,*i);free(d) ;return0;}
Running results
thevalueis3.140000thevalueis90