the difference between new and malloc

Answers were Sorted based on User's Feedback



the difference between new and malloc..

Answer / prakruthi

new automatically calls the constructor while malloc()
dosen't., also new being an operator, it can be overloaded.

since malloc returns a void pointer it is necessary to
explicitly typecast it into an appropriate type of pointer.
This gets completely avoided when we are using new operator.

Is This Answer Correct ?    25 Yes 2 No

the difference between new and malloc..

Answer / pushpankar mishra

malloc need type casting where as the new operator does not
require this incase if it is character type then char* is
needed in malloc where as for new we do not need this

Is This Answer Correct ?    10 Yes 1 No

the difference between new and malloc..

Answer / 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

the difference between new and malloc..

Answer / cl

The difference is the invocation of constructor: malloc
does not do it.

Is This Answer Correct ?    11 Yes 7 No

the difference between new and malloc..

Answer / swati

In case of Malloc we need to specify the size of memory for
our data types. But in case of New we do not need to specify
the size.

Is This Answer Correct ?    4 Yes 3 No

Post New Answer

More OOPS Interview Questions

What is OOPS and How it is different from Procedural Programming ?

23 Answers   HP, Infosys, Thyrocare,


2. Give the different notations for the class.\

0 Answers  


What is abstraction oop?

0 Answers  


Write a program to multiply 3x3 matrics

1 Answers  


difference between abstraction and encapsulation with progarammatic eg. hi,just recently i went for an interview .The interviewer asked what is the difference between abstraction and encapsulation with programmatic eg. I gave the answer as encapsulation mean hiding the relevant data which is not useful for the user, eg a electric fan .hiding the information how the electricity is converted into machanical energy. abtraction showing only the relevant data to the user eg electric fan. it look ,its color ,it design etc only relevant data. Then the interviewer asked me, give me some programmic eg .I Said Let assume a web form having control like textbox,button etc. The user can view textbox,button etc this is the eg of abstraction and when the user click on the button how he is redirected is not known by the user is the eg of the encapsulation. Am I Correct .was the answer given by me is perfect .now i am planing to go for an another interview should i give the same answer.IF not please suggest me a better answer.with some good eg Please help

1 Answers  






What is difference between abstraction and encapsulation?

0 Answers  


in the following, A D B G E C F Each of the seven digits from 0,1,2,3,4,5,6,7,8,9 is: a)Represented by a different letter in abov fig: b)Positioned in the fig abov so tht A*B*C,B*G*E,D*E*F are equal. wch does g represents? C

1 Answers   IonIdea,


What is use of overloading?

0 Answers  


I am developing a payroll system mini project.I used file concept in program for reading and writing.When the program is reloading into the memory that is if i execute next time the file was cleaned and adding data from the starting this is my problem.I want to strore the previous data and if i want to add any record that should be next of previous data.Please help me.

0 Answers  


write a C++ program for booking using constructor and destructor.

0 Answers   HAL,


how to swap the variables without using temp and operators

1 Answers  


What is abstraction in oops with example?

0 Answers  


Categories