Often in C++ Programs we use new operator to initialise an object or a pointer. Also as we know malloc() is also used for the same purpose then what is the difference between these two ? Or really is there any difference or not? So here is the answer.
|Sr. No.||New Operator||malloc()|
|1||However it is a feature of C++ and not in C – which is used to initialize a class object or a pointer.||malloc() is a library function and it was used in C/C++ language to allocate memory for n blocks at run time, it can also be used in c++ programming language. whenever a program needs memory to declare at run time we can use this function.|
|2||When you use new operator at that the constructor of the class is automatically executed||In case of malloc() the constructor is not executed automatically.|
|3||New works faster as compared to malloc()||Malloc() being a function works slowly as compared to new operator.|