//Andrew Alspaugh CS1A Chapter 9. P. 537. #1
/***************************************************************************
Allocate an Array
_____________________________________________________________________________
The purpose of this program is to dynamically allocate an array.
The focus of this program is to use a function to dynamically allocate the array
______________________________________________________________________________
INPUT:
size: user inputs array size which is passed to the function
OUTPUT:
*array: pointer variable for array starting address
*
*****************************************************************************/
#include <iostream>
using namespace std;
int*AllocateArray(int size);
int main()
{
//Data Dictionary
//input
int size;
//output
int* array;
int count;
//Input
cout << "Enter number of elements in array" << endl;
cin >> size;
//Process
array = AllocateArray(size);
//Output
for(int count = 0; count < size; count++)
{
cout << *(array + count) << "\t\t Memory Address is:" << &*(array + count) << endl;
}
delete [] array;
return 0;
}
//Function Definition of Allocate Array, this array creates a new variable for
//array and returns the new memory location
int* AllocateArray (int size)
{
int* array = new int[size];
for (int count = 0; count < size; ++count)
{
array[count] = count + 1;
}
return array;
}