why the memory allocated with new cant be freed using free()

Answers were Sorted based on User's Feedback



why the memory allocated with new cant be freed using free()..

Answer / durgalakshmi

new keyword does two things.
1) allocate memory using new operator
2) invokes the constructor.

so the allocated memory using new should be freed only by
delete which frees the memory by calling the destructor.

But free will not do these things.

Is This Answer Correct ?    3 Yes 0 No

why the memory allocated with new cant be freed using free()..

Answer / bharti

Because with new operator in C++ delete operator is used to
deallocate the memory. And with malloc() free() is used. S
it may not be supported by some of the compilers to free
memory with free() created by new.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More OOPS Interview Questions

i^=j; j^=i; i^=j; value of i,j

1 Answers  


why the memory allocated with new cant be freed using free()

2 Answers  


Why is polymorphism important in oop?

0 Answers  


What do you mean by overloading?

0 Answers  


what is polymorpsim? what are its types?

8 Answers  






Is data hiding and abstraction same?

0 Answers  


Explain the concept of abstracion and encapsulation with one example. What is the difference between them?

3 Answers   PCS,


Can private class be inherited?

0 Answers  


What is inheritance and how many types of inheritance?

0 Answers  


When is an object created and what is its lifetime?

4 Answers   IBM,


What is abstract class in oops?

0 Answers  


What is a class?

32 Answers   Infosys, TCS, Thylak,


Categories