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
Post A Comment:
0 comments: