Dynamic allocation and deallocation from the stack for all auto variables automatically. - C++ Operator

C++ examples for Operator:new

Description

Dynamic allocation and deallocation from the stack for all auto variables automatically.

Demo Code

#include <iostream>
#include <new>
using namespace std;
int main()/*ww  w.  j  a  va2 s .  com*/
{
   int numgrades, i;
   cout << "Enter the number of grades to be processed: ";
   cin  >> numgrades;
   int *grades = new int[numgrades];  // create the array
   for (i = 0; i < numgrades; i++)
   {
      cout << "  Enter a grade: ";
      cin  >> grades[i];
   }
   cout << "\nAn array was created for " << numgrades << " integers\n";
   cout << " The values stored in the array are:";
   for (i = 0; i < numgrades; i++)
      cout << "\n   " << grades[i];
   cout << endl;
   delete[] grades;  // return the storage to the heap
   return 0;
}

Result


Related Tutorials