Please send questions to
st10@humboldt.edu .
// quick second example: a DYNAMIC array filled in a FUNCTION
// (fillArray2)
//
// by: Sharon M. Tuttle
// last modified: 11-12-03
#include <iostream>
#include "fillArray2.h"
using namespace std;
int main()
{
// local variables
double *numArrayPtr; // LOOKS like double pointer ---
// BUT will set up to point to
// a double ARRAY, instead;
int size;
// use FUNCTION to fill array...
fillArray2(numArrayPtr, size);
// prove it has been filled...
for (int i=0; i<size; i++)
{
cout << "numArrayPtr[" << i << "]: "
<< numArrayPtr[i] << endl;
}
// IMPORTANT: to deallocate a dynamic array,
// YOU NEED THESE [ ]! (else, only the first
// element will be deallocated...)
delete [ ] numArrayPtr;
numArrayPtr = NULL; // good style: set to NULL
// after you deallocate what
// it points to...!
return 0;
}