Computer Science, asked by Mohit0, 1 year ago

Difference between malloc() and operator new.

Answers

Answered by ananthblaze
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 omegads03
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