When we allocate a memory by new why free is used to deallocate it why can't we use delete?
malloc delete
new free
why??
When we allocate a memory by new why free is used to deallocate it why can't we use delete?
malloc delete
new free
why??
I think you are under wrong impression. We should use 'free' if we use 'malloc' to allocate memory. And we should use 'delete' if we use 'new' to allocate the memory.
Moreever, in C++ you should be using new/delete always.
Yes, Rahul it correct... We need to use free to deallocate malloc memory and delete to dealocate New memory, otherwise it will lead it memory leaks... If we use New & delete the memory will be allocated & deallocated over constructors & destructors respectively...