// Example with New and Delete

/*
In order to request dynamic memory we use the operator new. 
new is followed by a data type specifier and -if a sequence of more than one element is required- 
the number of these within brackets [].


Since the necessity of dynamic memory is usually limited to specific moments within a program, 
once it is no longer needed it should be freed so that the memory becomes available again for other 
requests of dynamic memory. This is the purpose of the operator delete.
*/

#include "iostream.h"

int main()
{
    int    index, *point1, *point2;
    float  *float_point1, *float_point2 = new float;

    point1 = &index;
    *point1 = 77;
    point2 = new int;
    *point2 = 173;
    cout << " The values are " << index << "  " << 
                                   *point1 << "  " << *point2 << "\n";
    point1 = new int;
    point2 = point1;
    *point1 = 999;
    cout << " The values are " << index << "  " << 
            *point1 << "  " << *point2 << "\n\n";


    float_point1 = new float;
    *float_point2 = 3.14159;
    *float_point1 = 2 * (*float_point2);
    cout << " pi = " << *float_point2 << ", 2pi =  " << 
            *float_point1 << "\n";    
            
//  "Delete" should be used to delete memory allocated for a single element
    delete point1;
    delete point2;
    delete float_point1;
    delete float_point2;
   
    std::cin.get();
    return (0);   
}

