-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray
29 lines (25 loc) · 837 Bytes
/
Array
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
#include<iostream>
#include<array>
using namespace std;
int main()
{
array<int,4> a={1,2,3,4}; //initializing the array
int size=a.size();
for(int i=0;i<size;i++)
{
cout<<a[i]<<endl;
}
cout<<"Element at 2nd Index-->"<<a.at(2)<<endl; //print the element at index 2
cout<<"Empty or not-->"<<a.empty()<<endl; //tells whether an array is empty or not(0-false;1-true)
cout<<"First element-->"<<a.front()<<endl; //prints the first element of an array
cout<<"Last element-->"<<a.back()<<endl; //prints the last element of an array
}
------------------------OUTPUT----------------------
1
2
3
4
Element at 2nd Index-->3
Empty or not-->0
First element-->1
Last element-->4