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??
Printable View
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...
[QUOTE=Rahul C.;13122]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.[/QUOTE]
Hi Rahul, I am a new member of the group. I have a small doubt, what happens if we allocate memory using 'malloc' and deallocate memory using 'delete'. Is tihis possible..?