77.7k views
3 votes
Analyze and write a comparison of C's malloc and free functions with C++'s new and delete operators. Use safety as the primary consideration in the comparison

User Shalke
by
5.0k points

1 Answer

1 vote

Answer:

The C's malloc and free functions and the C++'s new and delete operators execute similar operations but in different ways and return results.

Step-by-step explanation:

- The new and delete operators return a fully typed pointer while the malloc and free functions return a void pointer.

-The new and delete operators do not return a null value on failure but the malloc/free functions do.

- The new/delete operator memory is allocated from free store while the malloc/free functions allocate from heap.

- The new/delete operators can add a new memory allocator to help with low memory but the malloc/free functions can't.

- The compiler calculates the size of the new/delete operator array while the malloc/free functions manually calculate array size as specified.

User Zerodf
by
5.1k points