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 the use of endl?
What is coupling in oop?
What is a multimap c++?
What is abstraction in oops with example?
What is class and example?
Differentiate between a constructor and a destructor in c++.
Explain the advantages of inheritance.
Explain about templates of C++.
What is the sequence of destruction of local objects?
What is static variable and difference between(const char *p,char const *p,const char* const p).
What is the c++ code?
Is overriding possible in c++?
What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?
What does scope resolution operator do?
Why struct is used in c++?