In C++, the list::back() function is used to access the last element of the list container directly. It returns a reference to the last element, which means the returned value can also be modified. This function is useful when we need quick access to the last element of a list without using iterators.
In C++, both back() and end() are related to the last element of a list, but they work differently. The back() function directly returns a reference to the last element, while the end() function returns an iterator pointing to the position after the last element of the list.
It has the following syntax.
It does not contain any parameter.
It returns the direct reference of the last element.
Here, we are going to discuss several examples to demonstrate the List back() Function Function.
This example demonstrates how to use the back() function to access the last element of a list.
Output:
back() is : @
Explanation:
In this example, back() function returns the last element of the list i.e @.
This example demonstrates how to use the back() function to modify the last element of a list directly.
Output:
Before modification: 10 20 30 40 After modification: 10 20 30 100
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India