home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / ANSICPP.ZIP / EX03003.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  499 b   |  18 lines

  1. // ex03003.cpp
  2. // the C++ free store: new with a dynamic array
  3. #include <iostream.h>
  4. #include <stdlib.h>
  5.  
  6. main()
  7. {
  8.     cout << "Enter the array size: ";
  9.     int size;
  10.     cin >> size;                    // get the array size
  11.     int *array = new int[size];        // allocate an array
  12.     for (int i = 0; i < size; i++)    // load the array
  13.         array[i] = rand();            // with random numbers
  14.     for (i = 0; i < size; i++)        // display the array
  15.         cout << '\n' << array[i];
  16.     delete array; // return the array to the free store
  17. }
  18.