-
Notifications
You must be signed in to change notification settings - Fork 7
/
array.cpp
46 lines (36 loc) · 959 Bytes
/
array.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
// array using stl function can do much more task and have a good library support
#include <iostream>
#include <array>
using namespace std;
int main()
{
// declaration
array<int, 4> a;
// assigning values
for (int i = 0; i < 4; i++)
{
cin >> a[i];
}
// declaration and assigning value
array<int, 4> arr = {1, 2, 3, 4};
// printing the array
for (int i = 0; i < 4; i++)
{
cout << a[i] << " ";
}
cout << endl;
for (int i = 0; i < 4; i++)
{
cout << arr[i] << " ";
}
cout << endl;
// finding the size of the array
cout << a.size() << " " << arr.size() << endl;
// accessing any element at given potion
cout << a[3] << " " << a.at(3) << endl;
// checking if the array is empty
cout << "Is array a empty ? " << a.empty() << endl;
// excessing first and last element
cout << arr.front() << " " << arr.back() << endl;
return 0;
}