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
write knight tour problem which is present in datastructure
Why is destructor used?
any one please tell me the purpose of operator overloading
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
What is difference between inheritance and polymorphism?
What is an interface in oop?
What is the example of polymorphism?
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
What is class in oop with example?
What is overloading in oops?
Prepare me a program for the animation of train
What is abstraction example?
Which is not an object oriented programming language?
class type to basic type conversion
How do you answer polymorphism?