Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I know the use of NEW keyword but i am confuse that what is main perpose of new keyword?
Some time we can do the same thing with other methods which we do with new keyword so need of clarification.
below is the example
I have created pointer object obj of class person and pass the address of object of student. I have write code in way so tell me the main difference?

What I have tried:

First code:

person *obj;
student s1;
obj=&s1;
obj.show();

2nd code:

person *obj;
obj=new student;
obj.show();
Posted
Updated 22-Oct-16 18:39pm

1 solution

The first question that comes in to mind, is Google banned in your region?
Quote:
Allocates memory for an object or array of objects of type-name from the free store and returns a suitably typed, nonzero pointer to the object.

new operator in C++
[^]

Hope, it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900