Memory Allocation: new and delete operators, dynamic constructor 

C++ provides two operators new and delete for dynamic memory usage. The new operator allocates memory from a free store while the delete operator returns the allotted memory to free store. For built-in types we use them as follows 
int * p, 
*arr ; 
p =new int; 
arr = new int[30]; 
delete p; 
delete [] arr; // we need not specify the size 
For user-defined types it is similar 
fraction *single, *vector; 
single = new fraction; 
vector = new fraction[30]; 


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: