C++ new Operator allocation and deallocation from the stack for all auto variables

Description

C++ new Operator allocation and deallocation from the stack for all auto variables

#include <iostream>
#include <new>
using namespace std;
int main()//from  w w  w  .  ja va 2s .  co  m
{
   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;
}



PreviousNext

Related