2.1.19.2 free


Description

Deallocates or frees a memory block that was allocated with malloc or calloc.

Syntax

void free( void * pmem )

Parameters

pmem
[input] Previously allocated memory block to be freed.

Return

None.

Examples

EX1

// This is a self contained sample program for the function free, 
// To run the program, enter the following command in the Script window:
//   free_ex1
// When it runs, the following meassage will be printed:
//   Allocated 100 bytes.
//   Before freeing: The memory contains: "TEST"; Length = 4
//   After freeing: The length of the string = 0
//
void    free_ex1()
{
    char  *pstr;
    pstr = (char*)malloc(100);
    printf("Allocated 100 bytes.\n");
    strcpy(pstr,"TEST");
    printf("Before freeing: The memory contains: \"%s\"; Length = %d\n",pstr,strlen(pstr));
    
    free(pstr);  // Demonstrating free
    printf("After freeing: The length of the string = %d\n",strlen(pstr));
}

Remark

Deallocates or frees a memory block that was allocated with malloc or calloc.

See Also

malloc

Header to Include

origin.h

Reference