COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
dynamic_array.cpp File Reference
#include <iostream>
Include dependency graph for dynamic_array.cpp:

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void )

Definition at line 5 of file dynamic_array.cpp.

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}