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 difference between new and malloc?

Answer Posted / shivi jain

new and delete are C++ specific features. They didn't exist in C. malloc is the old school C way to do things. Most of the time, you won't need to use it in C++.

malloc allocates uninitialized memory. The allocated memory has to be released with free.
calloc is like malloc but initializes the allocated memory with a constant (0). It needs to be freed with free.
new initializes the allocated memory by calling the constructor (if it's an object). Memory allocated with new should be released with delete (which in turn calls the destructor). It does not need you to manually specify the size you need and cast it to the appropriate type. Thus, it's more modern and less prone to errors.

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write knight tour problem which is present in datastructure

2597


Why is destructor used?

959


any one please tell me the purpose of operator overloading

2339


write a program using c++ to implement single contiguous memory mangement techniques.display the content of the main memory after yhe allocation of jobs and percentage of the wastage of the main memory

3174


What is difference between inheritance and polymorphism?

976


What is an interface in oop?

984


What is the example of polymorphism?

1024


Why is it so that we can have virtual constructors but we cannot have virtual destructors?

4808


What is class in oop with example?

1040


What is overloading in oops?

1092


Prepare me a program for the animation of train

2412


What is abstraction example?

1042


Which is not an object oriented programming language?

938


class type to basic type conversion

2338


How do you answer polymorphism?

1007