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
the maximum length of a character constant can be a) 2 b) 1 c) 8
hi all..i want to know oops concepts clearly can any1 explain??
What is buffer and example?
What is the iunknown interface?
What are default parameters? How are they evaluated in c++ function?
Can we make copy constructor private in c++?
Which one is better- macro or function?
Refer to a name of class or function that is defined within a namespace?
Can an interface inherit a class?
Explain the advantages of inheritance.
How do I write a c++ program?
How oops is better than procedural?
Define the process of handling in case of destructor failure?
Is c++ platform dependent?
Explain what is class definition in c++ ?