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

How come you find out if a linked-list is a cycle or not?

988


How much do coding jobs pay?

967


Is it possible to provide special behavior for one instance of a template but not for other instances?

1060


Can we use clrscr in c++?

1025


How many characters are recognized by ANSI C++?

1361


How can you force the compiler to not generate them?

975


When not to use object oriented programming?

1022


What is a constant? Explain with an example.

954


What do c++ programmers do?

1015


How to invoke a C function using a C++ program?

1016


What is guard code in c++?

1114


What is the difference between encapsulation and polymorphism?

1049


Comment on assignment operator in c++.

1076


Explain the register storage classes in c++.

1145


What is the point of polymorphism?

998