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 example, back function displays the last element of the vector named 'fruit'.