Open In App

How to Access the First Element of a Deque in C++?

Last Updated : 23 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In C++, deques also called double-ended queues are sequence containers that can perform insertions and deletions on both ends. In this article, we will learn how to access the first element of a deque in C++.

Example:

Input:
myDeque = {1,2,3,4,5}

Output: 
Deque Elements: 1 2 3 4 5
First Element: 1

Accessing the First Element of a Deque in C++

To access the first element of a std::deque in C++, we can use the std::deque::front() method which returns a reference to the first element of the deque. This function is suitable for accessing and manipulating the first element without modifying the deque's structure.

Syntax

deque_name.front();

Here:

  • deque_name: Denotess the deque container.
  • front(): This denotes the function used to access the first element of the deque.

C++ Program to Access the First Element of a Deque

The below program demonstrates how we can access the first element of a deque in C++.


Output
Deque Elements: 1 2 3 4 5
First Element: 1

Time Complexity: O(1)
Auxilliary Space: O(1)




Practice Tags :

Similar Reads