|
Answer» Both delete() and free() are USED to dynamically deallocate memory. - The free() function is a C library function that can ALSO be used in C++, whereas the keyword "delete" is a C++ keyword.
- The delete operator DELETES a pointer that was allocated using the new operator or a NULL pointer, whereas the free() function deletes a pointer that was allocated with the malloc(), calloc(), or realloc() functions or a NULL pointer.
- The delete operator in C++ invokes the class's destructor when it destroys the allocated memory, but the free() function does not; it just frees the memory from the HEAP.
|