What is main difference in new and delete? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is main difference in new and delete?

Cpp

10th Nov 2019, 6:12 PM
Sakshi Pachkhande
Sakshi Pachkhande - avatar
4 Answers
+ 6
new creat a object in heap memory or delete destroy objects in c++ but in java deletion works automatically.
10th Nov 2019, 6:22 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 1
The new keyword is used to allocate memory in the heap for the object you create. Whereas delete keyword is used to delete that object you created so that the memory occupied by the object can be freed. Now that memory will be available and can be used once again by the user for some other task.
10th Nov 2019, 6:29 PM
Avinesh
Avinesh - avatar
+ 1
And the most important is missed, which is if you forget to free memory from heap that's called Memory Leak which is a serious problem in your code.
10th Nov 2019, 6:39 PM
blACk sh4d0w
blACk sh4d0w - avatar
0
Thanks
10th Nov 2019, 6:23 PM
Sakshi Pachkhande
Sakshi Pachkhande - avatar