1#include<iostream>
2/*To get the last element of the array we first get the size
3 of the array by using sizeof(). Unfortunately, this gives
4 us the size of the array in bytes. To fix this, we divide
5 the size (in bytes) by the size of the data type in the array.
6 In our case, this would be int, so we divide sizeof(array)
7 by sizeof(int). Since arrays start from 0 and not 1 we
8 subtract one to get the last element.
9 -yegor*/
10int array[5] = { 1, 2, 3, 4, 5 };
11printf("Last Element of Array: %d", array[(sizeof(array)/sizeof(int))-1]);
1#include <array>
2std::array<int, 5> a {1, 2, 3, 4, 5};
3int i = a[a.size() - 1]; // The last variable stored in i