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

Vector End Function

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

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

C++ Vector end

This function provides an iterator pointing to the element past the last element in the vector container.

Syntax

Consider a vector v. Syntax would be:

Example

iterator it=v.end()

Parameter

It does not contain any parameter.

Return value

It yields an iterator that points to the element after the final one.

Example 1

Let's see a simple example.

Example

#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> v{10,20,20,40};
vector<int>::iterator it;
for(it=v.begin();it!=v.end();it++)
cout<<*it<<" ";
return 0;
}

Output:

Output

10 20 20 40

In this instance, the elements within the vector were traversed using the begin and end methods.

Example 2

Let's see another simple example.

Example

#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<string> v{"Welcome","to","javaCppTutorial"};
vector<string>::iterator it;
for(it=v.begin();it!=v.end();it++)
cout<<*it<<" ";
return 0;
}

Output:

Output

Welcome to javaCppTutorial

In this instance, sequences of vector elements have been traversed using the begin and end method.

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