Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Is c++ platform dependent?

1031


which of the following is not an secondary constant a) array b) real c) union

1753


Define a nested class. Explain how it can be useful.

1036


Is c++ still being used?

963


What is debug class?what is trace class? What differences are between them? With examples.

2129


Which bit wise operator is suitable for checking whether a particular bit is on or off?

970


How can a C function be called in a C++ program?

689


True or false, if you keep incrementing a variable, it will become negative a) True b) False c) It depends

2308


How do you define a class in oop?

1057


Is c++ free?

1032


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?

1441


What are the advantages and disadvantages of B-star trees over Binary trees?

993


What is the main purpose of c++?

1007


How can a called function determine the number of arguments that have been passed to it?

1074


Why is abstraction used?

1022