COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
dynamic_array.cpp
Go to the documentation of this file.
1
2#include <iostream>
3using namespace std;
4
5int main()
6{
7 int n;
8 cout << "Input the size of the array: ";
9 cin >> n;
10
11 // create a dynamic array
12 int * p = new int [n];
13
14 cout << "Enter " << n << " numbers: ";
15 for (int i = 0; i < n; ++i) {
16 cin >> p[i];
17 }
18
19 cout << "Contents of the array: ";
20 for (int i = 0; i < n; ++i) {
21 cout << p[i] << ' ';
22 }
23 cout << endl;
24
25 // free memory allocated to array
26 delete [] p;
27
28 return 0;
29}
int main()