Vector Back Function - C++ Programming Tutorial
C++ Course / STL Vector / Vector Back Function

Vector Back Function

BLUF: Mastering Vector 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: Vector Back Function

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

C++ Vector back

It gives a reference to the last element.

Syntax

Consider a vector v.Syntax would be:

Example

v.back();

Parameter

This function does not contain any parameter.

Return value

This function returns the last element of vector

Example

Let's see a simple example.

Example

#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<string>  fruit{"mango","apple","banana"};
cout<<fruit.back();
return 0; 
}

Output:

Output

banana

In this instance, the back method showcases the final element within the 'fruit' vector.

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