Namespaces
Variants
Views
Actions

free

From cppreference.com
< c‎ | memory
Revision as of 04:12, 3 June 2013 by P12 (Talk | contribs)

Defined in header <stdlib.h>
void free( void* ptr );

Deallocates the space previously allocated by malloc(), calloc() or realloc(). If ptr is null-pointer, the function does nothing.

The behavior is undefined if ptr does not match a pointer returned earlier by malloc(), calloc() or realloc(). Also, the behavior is undefined if the memory area referred to by ptr has already been deallocated, that is, free() or Template:rlpf has already been called with ptr as the argument and no calls to malloc(), calloc() or realloc() resulted in a pointer equal to ptr afterwards.

Contents

Parameters

ptr - pointer to the memory to deallocate

Return value

(none)

Example

#include <stdlib.h>
 
int main(int argc, char* argv[]) 
{
    int* ptr = (int*) malloc(sizeof(int));
    free(ptr);
    return 0;
}


See also