free的使用方式

 void free(void * ptr);

Deallocate space in memory 
A block of memory previously allocated using a call to malloc, calloc or realloc is deallocated, 
making it available again for further allocations.
Notice that this function leaves the value of ptr unchanged, hence it still points to the same (now invalid) location, 
and not to the null pointer.
Parameters
ptr
Pointer to a memory block previously allocated with malloc, calloc or realloc to be deallocated.
If a null pointer is passed as argument, no action occurs.
Return Value
(none)
Example
/* free example */
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int * bubber1, * buffer2, * buffer3;
    buffer1 = (int*)malloc(100*sizeof(int));
    buffer2 = (int*)calloc(100, sizeof(int));
    buffer3 = (int*)realloc(buffer2, 500*sizeof(int));
    free(buffer1);
    free(buffer3);
    return 0;
}
 
This program has no output.
Just demonstrates some ways to allocate and free dynamic memory using the cstdlib functions.
 
From:http://www.cplusplus.com/reference/clibrary/cstdlib/free/
 

你可能感兴趣的:(职场,free,休闲,使用方式)