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
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create
please visit this site you'll find my question this is my homework please answer it if you can http://easyscience.org/ib/lofiversion/index.php/t36168.html
What is difference between array and vector in c++?
What is double in c++?
What does namespace mean in c++?
What is the difference between mutex and binary semaphore?
What are mutator methods in c++?
What is the use of "new" operator?
Explain the importance of method overloading in C++?
Explain the register storage classes in c++.
Give two or more real cenario of virtual function and vertual object
What is the need of a destructor?
Are vectors passed by reference c++?
int age=35; if(age>80) {Console.WriteLine("Boy you are old");} else {Console.WrieLine("That is a good age");}
Can you pass an array to a function in c++?