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
What is abstraction example?
What is dynamic and static typing?
Consider the following C++ program
What is purpose of inheritance?
Describe public access specifiers?
Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).
What is the difference between a type-specific template friend class and a general template friend class?
What is the difference between structures and unions?
What does namespace mean in c++?
What does and I oop mean in text?
What is latest update of C++ ?
What is the type of 'this' pointer? When does it get created?
What is destructor oops?
What is the difference between public, private, and protected inheritance?
Difference between overloaded functions and overridden functions