Difference between malloc() and operator new.
Answers
Answered by
0
The most relevant difference is that the new operator allocates memory then calls the constructor, and delete calls the destructor then deallocates the memory. new calls the ctor of the object, delete call the dtor. malloc & free just allocate and release raw memory.
Answered by
0
The main difference between new and malloc is that new invokes the object's constructor and the corresponding call to delete invokes the object's destructor.new throws an exception on error, malloc returns NULL and sets errno. new is an operator and can be overloaded, malloc is a function and cannot be overloaded.
Similar questions