You must use the standard library function realloc. As the name suggests, it redistributes the memory block. Its prototype (contained in the title stdlib.h)
void *realloc(void *ptr, size_t size);
, ptr, size . malloc, realloc calloc. , realloc size , , , free .
realloc . , NULL, . ptr temp realloc . , malloc - malloc?
int *arr = malloc(10 * sizeof *arr);
int *temp = arr;
arr = realloc(arr, 5 * sizeof *arr);
if(arr == NULL) {
arr = temp;
}