Answers

Question and Answer:

  Home  C++ New And Delete

⟩ Can you please explain the difference between new and malloc and delete and free()

Delete is assocated with new and free(0 is associated with malloc()

New

Its an operator

delete is associated with new

It creates an object

It throws exceptions if memory is unavailable

Operator new can be overloaded

You can state the number of objects to be created.

malloc()

It’s a function

free() is associated with malloc()

It does not create objects

It returns NULL

This cannot be overloaded

You need to specify the number of bytes to be allocated.

 201 views

More Questions for you: