VOOZH about

URL: https://www.geeksforgeeks.org/cpp/list-back-function-in-c-stl/

⇱ list back() function in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

list back() function in C++ STL

Last Updated : 30 May, 2023

The list::back() function in C++ STL returns a direct reference to the last element in the list container. This function is different from the list::end() function as the end() function returns only the iterator to the last element.

Syntax

list_name.back();

Parameters

  • This function does not accept any parameter.

Return Value

  • Returns a direct reference to the last element in the list container.

Exception

  • Calling this function on an empty list container creates an undefined behavior in C++.

Example

The below program illustrates the list::back() function.


Output
30

Time Complexity: O(1)
Auxiliary Space: O(1)

Comment
Article Tags: