C++ Vector back()

It gives a reference to the last element.

cpp vector back() function

Syntax

Consider a vector v.Syntax would be:

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.

Output:

banana

In this example, back() function displays the last element of the vector named 'fruit'.





Latest Courses