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
Is c++ platform dependent?
which of the following is not an secondary constant a) array b) real c) union
Define a nested class. Explain how it can be useful.
Is c++ still being used?
What is debug class?what is trace class? What differences are between them? With examples.
Which bit wise operator is suitable for checking whether a particular bit is on or off?
How can a C function be called in a C++ program?
True or false, if you keep incrementing a variable, it will become negative a) True b) False c) It depends
How do you define a class in oop?
Is c++ free?
If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?
What are the advantages and disadvantages of B-star trees over Binary trees?
What is the main purpose of c++?
How can a called function determine the number of arguments that have been passed to it?
Why is abstraction used?