React.js
Angular
Ethical Hacking
Agile
AWS
BlockChain
Cassandra
Cloud
Salesforce
Scaled Agile
TOGAF
DevOps
GIT
Jenkins
Jira
Kibana
Linux
NGINX
Ansible
Artificial Intelligence
in C++ by
Click here to read more about DevOps

1 Answer

0 votes
by

Following are the differences between malloc() and operator new.

  • new is an operator, while malloc() is a function.
  • new returns exact data type, while malloc() returns void *.
  • new calls constructors( class instances are initalized and deinitialized automatically), while malloc() does not( classes won’t get initalized or deinitialized automatically
  • Syntax:
    1. int *n = new int(10); // initialization with new()
    2. str = (char *) malloc(15); //malloc()

free( ) is used on resources allocated by malloc( ), or calloc( ) in C

Delete is used on resources allocated by new in C++

Related questions

Madanswer
+1 vote
asked Jul 16, 2019 in C++ by Indian
+1 vote
asked Jul 16, 2019 in C++ by Indian
+1 vote
asked Jul 16, 2019 in C++ by Indian
+1 vote
+1 vote
asked Jul 16, 2019 in C++ by Indian
...