For dynamic arrays, we retrieve the last element of the vector and return its memory address.For static arrays, we simply retrieve the memory address of its last element.
xxxxxxxxxx
#include <vector> // If you're using dynamic arrays
#include <memory>
// Dynamic arrays
std::vector<int> s = {1, 2, 3, 4, 5};
int *ptr = &s[s.size() - 1]; // Pointer to the last element
// Static arrays
int *s = new int[ ];
int *ptr = &(*s)[last_element_number];
More DetailsFor dynamic arrays, we evaluate std::vector::size(), substact one, get the `result`th element of the vector and then set the pointer to its memory address. (&vector_name[vector_name.size() - 1])
For static arrays, we get the last value of the array and set the pointer to its memory address. (&(*array_name)[last_element_number])