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


Please Help Members By Posting Answers For Below Questions

the maximum length of a character constant can be a) 2 b) 1 c) 8

598


hi all..i want to know oops concepts clearly can any1 explain??

1678


What is buffer and example?

521


What is the iunknown interface?

674


What are default parameters? How are they evaluated in c++ function?

661






Can we make copy constructor private in c++?

591


Which one is better- macro or function?

644


Refer to a name of class or function that is defined within a namespace?

596


Can an interface inherit a class?

553


Explain the advantages of inheritance.

667


How do I write a c++ program?

590


How oops is better than procedural?

581


Define the process of handling in case of destructor failure?

569


Is c++ platform dependent?

627


Explain what is class definition in c++ ?

594