ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C++  >>  OOPS
 
 


 

 
 STL interview questions  STL Interview Questions
 OOPS interview questions  OOPS Interview Questions
 C++ General interview questions  C++ General Interview Questions
Question
the difference between new and malloc
 Question Submitted By :: Palnati
I also faced this Question!!     Rank Answer Posted By  
 
  Re: the difference between new and malloc
Answer
# 1
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 ?    1 Yes 1 No
Sanish Joseph
 
  Re: the difference between new and malloc
Answer
# 2
The difference is the invocation of constructor: malloc 
does not do it.
 
Is This Answer Correct ?    1 Yes 0 No
Cl
 
 
 
  Re: the difference between new and malloc
Answer
# 3
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 ?    1 Yes 0 No
Prakruthi
 

 
 
 
Other OOPS Interview Questions
 
  Question Asked @ Answers
 
What is abstraction?  6
what is a ststic variable and stiticfunction briefly explain with exmple and in which case we use HCL1
sir i want to know which posting to apply since i am BE CSE.. also want to know what are the rounds there for my interview...Expecting for ur valuable answer....  1
what is the function of 'this' operator ?  5
What do you mean by public, private, protected and friendly?  1
In c++ there is only virtual destructors, no constructors. Why?  2
what is virtual destructor TCS5
What is extreme programming?  2
What is multiple inheritance ? Ness-Technologies8
who is the founder of c++?  1
what are the disadvantages of C++? ATS4
Difference between new operator and operator new  2
WHAT IS THE DIFFERENCE BETWEEN ABSTRUCTION AND ENCAPSULATION? PLEASE EXPLAIN IT.  3
What do you mean by multiple inheritance and multilevel inheritance? Differentiate between them.  2
What is the correct syntax for inheritance? 1) class aclass : public superclass 2) class aclass inherit superclass 3) class aclass <-superclass  4
What is polymorphism? Explain with an example.  7
What are the different forms of polymorphism?? PCS5
what is virtual function? Infosys11
What do you mean by pure virtual functions?  4
what is object slicing? Wipro4
 
For more OOPS Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com