free(ptr);ptr is a pointer that has been created by using malloc or calloc.
ptr=realloc(ptr,newsize);This function allocates new memory space of size newsize to the pointer variable ptr ans returns a pointer to the first byte of the memory block. The allocated new block may be or may not be at the same region.
#include< stdio.h > #include< stdlib.h > define NULL 0 main() { char *buffer; /*Allocating memory*/ if((buffer=(char *) malloc(10))==NULL) { printf(“Malloc failed\n”); exit(1);
} printf(“Buffer of size %d created \n,_msize(buffer)); strcpy(buffer,”Bangalore”); printf(“\nBuffer contains:%s\n”,buffer); /*Reallocation*/ if((buffer=(char *)realloc(buffer,15))==NULL) { printf(“Reallocation failed\n”); exit(1); } printf(“\nBuffer size modified.\n”); printf(“\nBuffer still contains: %s\n”,buffer); strcpy(buffer,”Mysore”); printf(“\nBuffer now contains:%s\n”,buffer); /*freeing memory*/ free(buffer); }