-
Notifications
You must be signed in to change notification settings - Fork 6
/
experimentsWithArray.cpp
59 lines (47 loc) · 1.13 KB
/
experimentsWithArray.cpp
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
//Program to do experiments in accessing array
#include <iostream>
using namespace std;
int main() {
//first
int arr1[] = {1,2,3,4};
int size = sizeof(arr1)/sizeof(arr1[0]);
cout << "arr1 : ";
for(int i = 0; i < size; i++) {
cout << arr1[i] << " ";
}
//second
cout << "\narr1[-1] by default: " << arr1[-1];
//third
arr1[-1] = 10;
cout << "\narr1[-1] after assigning value: " << arr1[-1];
cout << endl;
//fourth
int arr2[4];
cout << "\nsizeof(arr2) where arr2 is int arr2[4]: " << sizeof(arr2);
//fifth
int *arr3;
arr3=arr2;
cout << "\nsizeof(arr3) where arr3 is int *arr3: " << sizeof(arr3);
cout << "\nsizeof(*arr3) where arr3 is int *arr3=arr2:" << sizeof(*arr3);
//sixth
int arr4[5]={1,2,3};
cout << "\narr4[5]={1,2,3} is: ";
for (int i = 0; i < 5; i++) {
cout << arr4[i] << " ";
}
//seventh
int arr5[5]={};
cout << "\narr5[5]={} is: ";
for (int i = 0; i < 5; i++) {
cout << arr5[i] << " ";
}
//eighth
cout << "\narr1[3/2]: " << arr1[3/2];
//deleting allocated memory
delete []arr1;
delete []arr2;
delete []arr3;
delete []arr4;
delete []arr5;
return 0;
}