why the memory allocated with new cant be freed using free()
Answers were Sorted based on User's Feedback
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 |
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 |
Write a program to reverse a string using recursive function?
what is oops
What are oops functions?
Can we have a private constructor ?
12 Answers HSBC, Ness Technologies, TCS, Wipro,
what is the difference between class and structure in C++?
What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }
Child cObj = new Parent() Wahts the output ?
What is a friend function & its advantage?
Difference between realloc() and free?
Why polymorphism is used in oops?
What is the highest level of cohesion?
what is difference between objects and function