C++ Deque empty()

Last Updated : 14 May 2026

Deque empty() Function

In C++, the deque::empty() function is used to check whether a deque container is empty or not. If the deque contains no elements, the function returns true; otherwise, it returns false. This function is useful before performing operations like deletion or accessing elements from a deque. It helps avoid errors when working with empty containers.

Syntax

It has the following syntax:

Parameter

It does not contain any parameter.

Return value

It does not return any value.

Examples of Deque empty() Function

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

Example 1: Check Whether a Deque is Empty Using empty()

This example demonstrates how to check whether a deque contains elements using the empty() function.

Output:

Deque is not empty

Explanation:

In this example, empty() function determines that the deque is not empty. Therefore, it returns false.

Example 2: Check an Empty Deque Using empty()

This example demonstrates how to verify whether a deque is empty using the empty() function.

Output:

Deque is empty

Explanation:

In this example, empty() function determines that the deque is empty. Therefore, it returns true.

Example 3: Use empty() Function After Removing Elements from a Deque

This example demonstrates how to use the empty() function after removing all elements from a deque.

Output:

Deque is empty

Next TopicC++ Deque