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

why destructor is not over loaded?

5 Answers  


Generally, in all C++ programs, texts are in white colour. Can we change the colour of the text(either input or output or both)? If so, help me out.

1 Answers  


Difference between new operator and operator new

2 Answers  


Can you explain polymorphism?

0 Answers  


What is difference between multiple inheritance and multilevel inheritance?

0 Answers  






write a program to enter a string like"sunil is a good boy and seeking for a job" not more than 10 characters including space in one line,rest characters should b in other line.if the next line starts from in between the previous word,then print whole word to next line.

0 Answers   Wipro,


Why is oop useful?

0 Answers  


How do you explain polymorphism?

0 Answers  


how to find the largest of given numbers in an array

2 Answers  


What are constructors in oop?

0 Answers  


Why static Function is used in C++?

4 Answers   TCS,


In which cases you use override and new base?

2 Answers  


Categories