-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc.cpp
More file actions
63 lines (54 loc) · 1.09 KB
/
Copy pathc.cpp
File metadata and controls
63 lines (54 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Include statements
#include <cstdlib>
#include <iostream>
using namespace std;
// Main function
int main()
{
// Get user input
int size1 = 0;
cout << "Enter size of array1:\n";
cin >> size1;
if (size1 < 0)
size1 = 0;
// Get user input
int size2 = 0;
cout << "Enter size of array2:\n";
cin >> size2;
if (size2 < 0)
size2 = 0;
// Process array1
int * array1 = new int[size1];
cout << "array1:\n";
for (int i = 0; i < size1; i++)
{
array1[i] = 17;
cout << array1[i] << " ";
}
cout << endl;
// Location A
delete [] array1;
// Process array2
int * array2 = new int[size2];
cout << "array2:\n";
for (int i = 0; i < size2; i++)
{
//Step 3
cout << array2[i] << " ";
array2[i] = 42;
cout << array2[i] << " ";
}
cout << endl;
// Location B
// Print array1
cout << "array1:\n";
for (int i = 0; i < size1; i++)
cout << array1[i] << " ";
cout << endl;
// Location C
array1 = NULL;
// Return memory to O/S
delete [] array2;
array2 = NULL;
return 0 ;
}