C++ Deque size()

Last Updated : 14 May 2026

Deque size() Function

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.

Syntax

It has the following syntax:

where, return_type is an unsigned integral type.

Parameter

It does not contain any parameter.

Return value

It returns the number of elements in the deque container.

Examples of Deque size() Function

Here, we are going to discuss several examples to demonstrate the deque size() function.

Example 1: Find the Size of a Deque Using size()

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.

Example 2: Check the Size After Removing Elements from a Deque

This example demonstrates how the size() function changes after removing elements from a deque.

Output:

Initial size: 4
Size after deletion: 2

Example 3: Find the Size of a String Deque Using size()

This example demonstrates how to determine the number of string elements in a deque using the size() function.

Output:

Size of deque: 3

Next TopicC++ Deque