/*prototype of realloc*/
void *realloc(void *ptr, size_t newsize);
/*use*/
dyn_array = realloc(dyn_array, (dyn_array_size + 1) * sizeof(int));
/*
adds one more space to dyn_array
you need stdlib.h for this
*/
#include <stdio.h>
int main () {
char *ptr;
ptr = (char *) malloc(10);
strcpy(ptr, "Programming");
printf(" %s, Address = %u
", ptr, ptr);
ptr = (char *) realloc(ptr, 20); //ptr is reallocated with new size
strcat(ptr, " In 'C'");
printf(" %s, Address = %u
", ptr, ptr);
free(ptr);
return 0;
}
void *realloc(void *ptr, size_t size)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *ptr = (int *)malloc(sizeof(int)*2);
int i;
int *ptr_new;
*ptr = 10;
*(ptr + 1) = 20;
ptr_new = (int *)realloc(ptr, sizeof(int)*3);
*(ptr_new + 2) = 30;
for(i = 0; i < 3; i++)
printf("%d ", *(ptr_new + i));
getchar();
return 0;
}