the difference between new and malloc

Answer Posted / sanish joseph

both malloc and new functions are used for dynamic memory
allocations and the basic difference is: malloc requires a
special "typecasting" when it allocates memory for eg. if
the pointer used is the char pointer then after the
processor allocates memory then this allocated memory needs
to be typecasted to char pointer i.e (char*).but new does
not requires any typecasting. Also, free is the keyword used
to free the memory while using malloc and delete the keyword
to free memory while using new, otherwise this will lead the
memory leak.

Is This Answer Correct ?    13 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why can't we have instance(stack) of a class as a member of the same class like eg.Class A{A obj;} as we can have self refential pointer

1910


Can a destructor be called directly?

813


What is encapsulation and abstraction? How are they implemented in C++?

862


what type of questions

1900


What is basic concept of oop?

907


• What are the desirable attributes for memory managment?

1956


What is polymorphism and types?

850


What is overloading and its types?

828


Why is abstraction needed?

764


What is an advantage of polymorphism?

826


What is difference between polymorphism and inheritance?

821


What is encapsulation in oops?

770


What is byval and byref? What are differences between them?

1959


Why is there no multiple inheritance?

776


What is encapsulation process?

796