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 come you find out if a linked-list is a cycle or not?
How much do coding jobs pay?
Is it possible to provide special behavior for one instance of a template but not for other instances?
Can we use clrscr in c++?
How many characters are recognized by ANSI C++?
How can you force the compiler to not generate them?
When not to use object oriented programming?
What is a constant? Explain with an example.
What do c++ programmers do?
How to invoke a C function using a C++ program?
What is guard code in c++?
What is the difference between encapsulation and polymorphism?
Comment on assignment operator in c++.
Explain the register storage classes in c++.
What is the point of polymorphism?