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 program in c++ to print the numbers from n to n2 except 5 and its multiples
Explain "const" reference arguments in function?
What is a singleton class c++?
What is the difference between encapsulation and polymorphism?
Can a list of string be stored within a two dimensional array?
Declare a pointer to a function that takes a char pointer as argument and returns a void pointer.
What are the 3 principles of oop?
Write a program to show polymorphism in C++?
Discussion on error handling of C++ .
Define private, protected and public access control.
What is namespace std; and what is consists of?
Explain stack unwinding.
What is the difference between multiple and multilevel inheritance in c++?
Is it possible to get the source code back from binary file?
Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .