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
i got a backdoor offer in process global,Bangalore..Can i work with it?
What is constant in c++ with example?
What are the features of oop?
Write a note about the virtual member function?
What is c++ hiding?
How to generate random numbers in C++ with a range?
How do you invoke a base member function from a derived class in which you have not overridden that function?
What is the use of ::(scope resolution operator)?
Which software is best for programming?
What is and I oop mean?
Define pointers?
Why are pointers used?
What is virtual destructor ans explain its use?
Describe Trees using C++ with an example.
Describe the syntax of single inheritance in C++?