C Language: Pointers 30

/* 
Example of realloc()
*/
#include <stdio.h>
#include <stdlib.h>
#include<string.h>

int main () {
   char *str;

   /* Initial memory allocation */
   str = (char *) malloc(13);
   strcpy(str, "rajeshshukla");
   printf("String = %s,  Address = %u\n", str, str);

   /* Reallocating memory */
   str = (char *) realloc(str, 30);
   strcat(str, "catalyst.com");
   printf("String = %s,  Address = %u\n", str, str);

   free(str);
   
   return(0);
}
/* Output */
String = rajeshshukla,  Address = 12194752
String = rajeshshuklacatalyst.com,  Address = 12194752