In C++, the deque::size() function is used to determine the number of elements currently present in a deque container. It returns the total count of elements stored in the deque. This function is useful when checking whether a deque contains elements or when controlling loops and conditions based on the container size. The size changes dynamically as elements are added or removed from the deque.
It has the following syntax:
where, return_type is an unsigned integral type.
It does not contain any parameter.
It returns the number of elements in the deque container.
Here, we are going to discuss several examples to demonstrate the deque size() function.
This example demonstrates how to determine the number of elements in a deque using the size() function.
Output:
size of deque is :0 size of deque is :3
Explanation:
In this example, when deque 'd' is empty then the size() function returns 0. When three elements are added in the deque container then size() function returns 3.
This example demonstrates how the size() function changes after removing elements from a deque.
Output:
Initial size: 4 Size after deletion: 2
This example demonstrates how to determine the number of string elements in a deque using the size() function.
Output:
Size of deque: 3
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