ALLOCATING STORAGE WITH malloc malloc allocates a block of bytes of at least the desired size and returns a pointer, or null if a large enough chunk of memory location could not be found double tptr /an array of n double tptr= malloc(n* sizeof(double)) if (tptr=NULL) {prin“ Couldn t allocate% elementsin”,n return 1; out of memory error, quit PROGRAM MINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu ol Hone Kone
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu ALLOCATING STORAGE WITH malloc malloc allocates a block of bytes of at least the desired size and returns a pointer, or NULL if a large enough chunk of memory location could not be found. double *tptr /* an array of n double */ .. tptr = malloc(n* sizeof(double)); if (tptr = NULL) { printf(“Couldn’t allocate %I elements\n”, n); return 1; /* out of memory error, quit */ }
FREE STORAGE WITH free To free the memory with free free(tptr) PROGRAMMINGMETHDOLODGY AND SOFTWAREENGINEERING 港城市大 Copyrighto1998 Angus Wu
PROGRAMMING METHDOLODGY AND SOFTWARE ENGINEERING Copyright©1998 Angus Wu FREE STORAGE WITH free To free the memory with free: free(tptr);