-
Notifications
You must be signed in to change notification settings - Fork 0
/
001array.cpp
35 lines (34 loc) · 1.02 KB
/
001array.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
#include<iostream>
#include<array>
using namespace std;
int main(){
// normal array
int basic[3]= {1,2,3};
// STL Array
array<int ,4> a= {1,2,3,4};
int size = a.size();
for(int i =0 ; i<size ; i++){
cout<<"Index at "<<i <<" Element Found "<<a[i]<<endl;
}
// access element direct from the index
cout<<"Element at 2nd Index "<<a[2]<<endl;
// access element dirrect by index IN STL
cout<<"Element at 2nd Index "<<a.at(2)<<endl;
//array is empty or not empty , if empty return 1 if not return 0
cout<<"is array are empty "<<a.empty()<<endl;
// getting the first element of the array
cout<<"Front Element : "<< a.front()<<endl;
// getting the last element of the array
cout <<"Back Element : "<< a.back()<<endl;
}
/*
Index at 0 Element Found 1
Index at 1 Element Found 2
Index at 2 Element Found 3
Index at 3 Element Found 4
Element at 2nd Index 3
Element at 2nd Index 3
is array are empty 0
Front Element : 1
Back Element : 4
*/