Dynamic Memory Allocation (cont)
Example:int * vec;if ((vec=(int*) malloc(ARR_LNG*sizeof(int)))==NULL){ fprintf(stderr,”cannot allocate\n”); exit(1);}if ((vec = (int*)realloc(vec, NEW_ARR_LNG*sizeof(int))) ==NULL) { fprintf(stderr,”cannot allocate\n”); exit(1);}
Dynamically allocated memory (only) can be returned to the system using the function “void *free(old_ptr)”