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>
3
using namespace
std;
4
5
int
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
}
main
int main()
Definition
dynamic_array.cpp:5
Module8
Sample Code
Pointers
dynamic_array.cpp
Generated on Sun Sep 29 2024 16:39:53 for COMP2113 by
1.12.0