queue::back() function in C++ STL

In C++, the standard library gives us the facility to use the Queues as a type of container adaptors which operate in a first in first out (FIFO) type of arrangement. The queue::back() is a C++ Standard Library function which is used to get the last element of a queue.

Syntax

Queue_Name.back( );

Parameter: The queue::back() function does not accepts any parameter.

Return value: The queue::back() function returns the reference the last element of the queue container.

Example of queue::back() Function

#include <iostream> 
#include <queue> 
using namespace std; 
  
int main() 
{ 
    queue<int> QUE; 
    QUE.push(1); 
    QUE.push(4); 
    QUE.push(3); 
    QUE.push(7); 
    
    cout << QUE.back(); 
    return 0; 
} 

Output

7

This article is written by

Pratik Singhal

Pratik Singhal

Please comment below, if you have any doubts or find any error in the above article.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
[gravityforms id="5" description="false" titla="false" ajax="true"]