English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++ The List back() function returns the last element of the list. It provides a direct reference to the element.
The end() function returns an iterator to the element, while the back() function returns a direct reference to the same element.
reference back();
It does not contain any parameters.
It returns a direct reference to the last element.
Let's see a simple example
#include#include using namespace std; int main() { std::list li={+','-','*','@'}'; std::cout << "back() is:" << li.back() << std::endl; return 0; }
Output:
back() is: @
In this example, the back() function returns the direct reference to the last element of the list, that is, @.