free() function and delete operator are used to deallocate the memory a pointer is holding.
free() function is used when the memory is allocated to the pointer by either malloc(),calloc() or realloc() function, whereas delete operator is used when the memory is allocated to the pointer using new operator.
For example;
int main()
{
/* free() is used to free memory assigned with malloc() or calloc() */
int *pointer1 = (int *)malloc(sizeof(int));
int *pointer2 = (int*) calloc (10,sizeof(int));
free(pointer1);
free(pointer2);
/* delete is used to free memory assigned with new operator */
int *pointer3 = new int;
delete pointer3;
getchar();
return 0;
}
0 Comment(s)