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

How do you answer polymorphism?

0 Answers  


What are the three main types of variables?

0 Answers  


What is encapsulation c#?

0 Answers  


In multiple inheritance , to create sub class object , is there need to create objects for its superclasses??? in java and c++ both. Actually i have some information that is , all available members from its superclasses , memory created in subclass obj , so no need to create object for its superclasses...??? Thanks in Advance

1 Answers  


Explain polymorphism? What r the types of polymorphism? pls give examples?

4 Answers   HCL,






What are the access specifiers avaible in c++?

4 Answers  


Which method cannot be overridden?

0 Answers  


This program numbers the lines found in a text file. Write a program that reads text from a file and outputs each line preceded by a line number. Print the line number right-adjusted in a field of 3 spaces. Follow the line number with a colon, then one space, then the text of the line. You should get a character at a time and write code to ignore leading blanks on each line. You may assume that the lines are short enough to fit within a line on the screen. Otherwise, allow default printer or screen output behavior if the line is too long (i.e., wrap or truncate). A somewhat harder version determines the number of spaces needed in the field for the line numbers by counting lines before processing the lines of the file. This version of the program should insert a new line after the last complete word that will fit within a 72-character line.

0 Answers  


What is difference between abstraction and encapsulation?

0 Answers  


What is the difference between and interface and an abstract class ?

4 Answers   IBM, Infosys, Ness Technologies,


who is the father of OPPS

4 Answers   Infosys, TCS,


The company is a fake company asking for money of RS10000 while training and not offering a job after training. My humble request to you people not to attend Astersys interview

1 Answers   Astersys,


Categories