In the C++ programming language, the deque (double-ended queue) is a container class that is a part of the Standard Template Library (STL). It allows fast insertion and deletion of elements at both the beginning and the end of the deque.
In C++, the Deque end() function is commonly utilized to return an iterator that points to the "past-the-last" element of the deque. If the deque container is empty, the end() function returns the same as the begin() function. The "past-the-last" is the element that is used to follow the last element, and it marks the end boundary for forward iteration.
It has the following syntax:
It returns an iterator referring to the past-the-last element. If the deque is constant, it also returns the const_iterator.
Here, we are going to discuss several examples to demonstrate the deque end() function.
This example demonstrates how to traverse all deque elements using the begin() and end() functions.
Output:
10 20 30 40 50
Explanation:
In this example, we have taken a deque of integers and traversed this deque using an iterator. After that, we use the begin() function that gives the iterator to the first element, while the end() function marks the position just after the last element. Finally, the loop executes until itr reaches the end() function, which prints all elements of the deque in order.
This example demonstrates how to access the last element of a deque using the end() function.
Output:
Last element of the deque is: DSA
Explanation:
In this example, we have created a deque of strings and use the end() function to get an iterator pointing past the last element. After that, by decrementing the iterator with --it, we move it to the actual last element, which is then displayed as "DSA".
This example demonstrates how to use the STL find() algorithm with the end() function to search elements in a deque.
Output:
Element is found in the Deque: 25
Explanation:
In this example, we have created a deque of integers and also used the find() algorithm to find the value 25 with the begin() and end() functions. If the iterator returned is not equal to the dq.end() function, it specifies that the element is available in the deque, and the found value is displayed on the screen.
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India