C++/why new operator in cpp
QUESTION: 1>c supports stack memory allocation for objects by simple invoking costructor with out using "new".but what is need to to introduce 'new' operator in cpp(although malloc and calloc were doing the job in 'c')?
2>what is difference between new int and new int(5),and how 'delete' or 'delete' work in each case?
3>is the above statement execute any wrapper/primitive type of constructor?if yes how if know how it allocates memory?
thanks in advance..
ANSWER: See http://www.yolinux.com/TUTORIALS/Cpp-DynamicMemory.html
---------- FOLLOW-UP ----------
QUESTION: sir 2> and 3> are not clear .whether new only operates on constructor?if yes then how it allocates memory for primary type?plz elaborate..
thank you for quick response.
Where T is some type,
new T ; allocates memory by calling operator new()
If T has a non-trivial default constructor, it is then invoked to initialize the object.
If T is a type with no constructor (say int), this step is skipped.