List Back Function - C++ Programming Tutorial
C++ Course / Dynamic Programming / List Back Function

List Back Function

BLUF: Mastering List Back Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: List Back Function

C++ is renowned for its efficiency. Learn how List Back Function enables low-level control and high-performance computing in the tutorial below.

C++ List back

The back function in C++ List retrieves the final element of the list, offering direct access to it.

Difference between back and end function

The end method provides an iterator pointing to the element, whereas the back function gives a direct reference to that specific element.

Syntax

Example

reference back();

Parameter

It does not contain any parameter.

Return value

It provides the explicit pointer to the final element.

Example

Let's see a simple example

Example

#include <iostream>
#include<list>
using namespace std;
int main()
{
   
    std::list<char> li={'+','-','*','@'};
    std::cout <<"back() is :"<< li.back() << std::endl;
    return 0;
}

Output:

Output

back() is : @

In this instance, the back method retrieves the final element of the collection, which is the symbol @.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience