get last element of array c++ code example
Example 1: find last element of an array c++
int arr={1,2,3,4,5,6};
int length=sizeof(arr)/sizeof(int);
int lastElement=aar[length-1];
Example 2: c++ get last element in array
#include<iostream>
int array[5] = { 1, 2, 3, 4, 5 };
printf("Last Element of Array: %d", array[(sizeof(array)/sizeof(int))-1]);
Example 3: How to get the last element of an array in C++ using std::array
#include <array>
std::array<int, 5> a {1, 2, 3, 4, 5};
int i = a[a.size() - 1];