C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C++ Vector back()It gives a reference to the last element. SyntaxConsider a vector v.Syntax would be: v.back(); ParameterThis function does not contain any parameter. Return valueThis function returns the last element of vector ExampleLet's see a simple example. #include<iostream> #include<vector> using namespace std; int main() { vector<string> fruit{"mango","apple","banana"}; cout<<fruit.back(); return 0; } Output: banana In this example, back() function displays the last element of the vector named 'fruit'.
Next TopicVector front() Function
|