The difference between malloc and new

1. The new and delete are operator which can be overloaded. They  are only available in C++. The malloc and free are standard library functions which can be used both in C and C++.

2.The new of an object invoke the constructor function and the delete of an object invoke the destructor function. The malloc and free only assign memory space but do not invoke constructor or destructor functions.

3. The new returns pointer to corresponding object, while malloc returns void pointer.

Advertisements
This entry was posted in C++. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s