//Cameron Pham CS1A Chapter 9, p. 537, #1
//
/******************************************************************************
* ALLOCATE ARRAY OF INTEGERS
* ______________________________________________________________________________
* This program accepts an integer argument indicating the number of elements to
* allocate. The function dynamically allocates an array of integers.
*******************************************************************************/
#include <iostream>
using namespace std;
// Function prototype
int* allocateArray(int size);
int main()
{
// Initialize variables
int size; // Number of elements in the array
int* numbers; // Pointer to the dynamically allocated array
// Ask the user for the number of elements
cout << "Enter the number of elements to allocate: ";
cin >> size;
// Allocate the array and receive its address
numbers = allocateArray(size);
// Display the allocated array elements
cout << "Array successfully allocated with "
<< size << " elements." << endl;
// Release dynamically allocated memory
delete[] numbers;
numbers = nullptr;
return 0;
}
// Dynamically allocate an integer array and return its pointer
int* allocateArray(int size)
{
int* array = new int[size];
return array;
}