c++ access second last element of vector

// Accessing the second last element of a vector in C++
std::vector<int> vec = {1, 2, 3, 4, 5};
int secondLastElement = vec.at(vec.size() - 2); // Subtract 2 from the size of the vector to get the index of the second last element