Académique Documents
Professionnel Documents
Culture Documents
h>
void main() { char *buffer; clrscr(); /*allocating memory*/ buffer=(char *)malloc(10*sizeof(char)); if(buffer==NULL) { printf("Insufficient Memory"); exit(0); } printf("Buffer of size 10 created\n"); strcpy(buffer,"Hyderabad"); printf("\nBuffer contains: %s\n",buffer); /*reallocation*/ buffer=(char *)realloc(buffer,25*sizeof(char)); if(buffer==NULL) { printf("Insufficient Memory"); exit(0); } printf("\nBuffer size modified\n"); printf("\nNew buffer size is 25\n"); printf("\nBuffer still contains: %s \n",buffer); strcpy(buffer,"Secunderabad"); printf("\nBuffer now contains: %s",buffer); /*freeing the memory*/ free(buffer); getch(); } /*to check overflow*/ /*to check overflow*/