GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 29 of 203    Print  
What is the difference between operator new and the new operator?

  
Total Answers and Comments: 5 Last Update: October 19, 2009     Asked by: suman 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: madhav_kelkar
 
This is what happens when you create a new object: 1. the memory for the object is allocated using "operator new". 2. the costructor of the class is invoked to properly initialize this memory. As you can see, the new operator does both 1 and 2. The operator new merely allocates memory, it does not initialize it. where as the new operator also initializes it properly by calling the constructor.

Above answer was rated as good by the following members:
bobsEmc2
November 08, 2005 08:14:09   #1  
madhav_kelkar Member Since: November 2005   Contribution: 1    

RE: What is the difference between operator new and th...
This is what happens when you create a new object: 1. the memory for the object is allocated using operator new . 2. the costructor of the class is invoked to properly initialize this memory. As you can see the new operator does both 1 and 2. The operator new merely allocates memory it does not initialize it. where as the new operator also initializes it properly by calling the constructor.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
January 28, 2006 05:30:05   #2  
gaurav_web Member Since: November 2005   Contribution: 1    

RE: What is the difference between operator new and th...

operator new() will do the operator overloading new operator for memory allocation.


 
Is this answer useful? Yes | No
August 08, 2008 06:39:25   #3  
vsvraju Member Since: August 2008   Contribution: 5    

RE: What is the difference between operator new and the new operator?
Operator new mean overloading the operator 'new' giving your own defintion for the existing 'new' operator.
 
Is this answer useful? Yes | No
June 12, 2009 08:50:29   #4  
gunjan.chandra Member Since: April 2009   Contribution: 7    

RE: What is the difference between operator new and the new operator?
'new' operator allocates new instance of object from the heap thus utilising the most appropiate constructor for the argument.

Operator new is the mechanism of overriding the default heap allocation logic.

 
Is this answer useful? Yes | No
October 16, 2009 02:11:43   #5  
satheesh83 Member Since: March 2009   Contribution: 1    

RE: What is the difference between operator new and the new operator?

New operator allows to allocate a memory from the heap so a new instance of
a class is created but operator New is used to overload the (new) operator just
like overloading of other operators.


Additionally:

The term "operator new" is used incase when u are overloading the global "new"
operator. We can overload new operator just as any other operators i.e
+ - * etc.

The term "new operator" is used in case of dynamic allocation of memory. When a
variable is allocated memory dynamically the new operator is used.


Eg:

int *p new int;

//here p is pointer to integer. So in order to allocate memory for it we have
used the new operator.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape