Shall we use 'free' to free memory assigned by new, What are
the further consequences??

Answer Posted / krishnarao panchadi

Syntactically we can use "free" in place of "delete". But
semantically it is senseless as it wont call the destructor.

Note that, deallocating is not the only purpose of
using "delete". The destructor should also be called if you
call the constructor(while creating the object).
Failing to call "delete" may lead to system crash.

Using "free" wont call the desturctor.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why the usage of pointers in C++ is not recommended ?

901


Write about a nested class and mention its use?

630


How new/delete differs from malloc()/free?

620


How can you link a c++ program to c functions?

624


What is meaning of in c++?

674






What is meant by a delegate?

610


Why Pointers are not used in C++?

624


Write a short code using c++ to print out all odd number from 1 to 100 using a for loop

588


Write about the stack unwinding?

630


Why is swift so fast?

626


What is a pointer how and when is it used?

580


What is basic if statement syntax?

570


Do you know about latest advancements in C++ ?

662


What are the restrictions apply to constructors and destructors?

645


What is the importance of mutable keyword?

585