Possible Duplicate:
What is the difference between new/delete and malloc/free?
Could someone please revise/edit the below - the differences between malloc and new - and see if everything is correct, or am I missing something or got something wrong? Thank you,
Both malloc and new are used for Dynamic Memory Allocation.
malloc is a C function, whereas new is a C++ operator.
malloc requires a special typecasting when it allocates memory dynamically,
whereas new does not require any typecasting.
Whenever we use new for allocating memory, it also invokes any required constructors, whereas malloc doesn't do that.
malloc can fail and returns a NULL pointer if memory is exhausted, whereas new never returns a NULL pointer, but indicates failure by throwing an exception instead.
While using malloc, free is the C function used to free up the allocated memory.
While using new, delete is the C++ operator used to free up the allocated memory AND call any required destructors.