Difference between malloc() and operator new.
Answers
Answered by
0
Both are used for same purpose, but still they have some differences, the differences are:
new is an operator whereas malloc() is a library function.
new allocates memory and calls constructor for object initialization.
But malloc() allocates memory and does not call constructor.
new is an operator whereas malloc() is a library function.
new allocates memory and calls constructor for object initialization.
But malloc() allocates memory and does not call constructor.
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