Scroll to navigation

std::list::back(3) C++ Standard Libary std::list::back(3)

NAME

std::list::back - std::list::back

Synopsis

reference back(); (1) const_reference back() const; (2)

Returns a reference to the last element in the container.

Calling back on an empty container causes undefined behavior.

Parameters

(none)

Return value

Reference to the last element.

Complexity

Constant.

Notes

For a non-empty container c, the expression c.back() is equivalent to *std::prev(c.end()).

Example

// Run this code

#include <cassert> #include <list>

int main() {
std::list<char> letters{'a', 'b', 'c', 'd'};
assert(letters.back() == 'd'); }

See also

front access the first element
(public member function) rbegin returns a reverse iterator to the beginning crbegin (public member function) (C++11) end returns an iterator to the end cend (public member function) (C++11)

2026.11.10 http://cppreference.com