Google News
logo
CPP - Interview Questions
What is the difference between new() and malloc()?
* new() is a preprocessor while malloc() is a function.

* There is no need to allocate the memory while using "new" but in malloc() you have to use sizeof().

* "new" initializes the new memory to 0 while malloc() gives random value in the newly allotted memory location.

* The new() operator allocates the memory and calls the constructor for the object initialization and malloc() function allocates the memory but does not call the constructor for the object initialization.

* The new() operator is faster than the malloc() function as operator is faster than the function.
Advertisement