What is the difference between creating an object,
using 'new' and using 'malloc'?
Answer Posted / sundaram
?new? is used for dynamic memory allocation in C++,
?malloc()? is used for dynamic memory allocation in C.
?new? allocates memory on heap.
?malloc()? allocates memory on heap.
?new? is operator,
?malloc()? is function
?new? returns memory pointer to the correct object on
SUCCESS,
?malloc? returns pointer to void void* on success
?new? throws exception called ?bad_alloc? on FAILURE,
?malloc? returns NULL on FAILURE
?new? is 2 step process
(i) First Allocates memory for a given object
(ii) Calls corresponding destructor if required
?malloc? is one step process ie it allocating only memory.
| Is This Answer Correct ? | 7 Yes | 2 No |
Post New Answer View All Answers
How compile and run c++ program in turbo c++?
Can the creation of operator** is allowed to perform the to-the-power-of operations?
What is coupling in oops?
What are the different types of comments allowed in c++?
Can we use pointers in c++?
Write A Program to find the ambiguities in Multiple Inheritance? How are they resolved.(Virtual Functions)
What is the difference between structure and class?
Why is polymorphism useful?
How is polymorphism achieved?
Can I run c program in turbo c++?
Is it possible to get the source code back from binary file?
What is implicit pointer in c++?
What is ctime c++?
Who was the creator of c++?
Why is oop useful?