Deque Cbegin Function - C++ Programming Tutorial
C++ Course / STL Queue & Stack / Deque Cbegin Function

Deque Cbegin Function

BLUF: Mastering Deque Cbegin Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Deque Cbegin Function

C++ is renowned for its efficiency. Learn how Deque Cbegin Function enables low-level control and high-performance computing in the tutorial below.

C++ Deque cbegin

The cbegin function in C++ for Deque provides a constant iterator that points to the initial element within the deque container. This iterator retains the flexibility to be both incremented and decremented similar to the iterator obtained from the begin function. In cases where the container is devoid of elements, the iterator returned will be equivalent to the cend.

Syntax

Example

const_iterator cbegin();

Parameter

It does not contain any parameter.

Return value

It yields a fixed iterator indicating the start of the collection.

Example 1

Let's see a simple example

Example

#include <iostream>
#include<deque>
using namespace std;
int main()
{
 deque<string> fruit={"mango","apple","banana","kiwi"};
 deque<string>::const_iterator itr;
 itr=fruit.cbegin();
  cout<<*itr;
  return 0;
}

Output:

In this instance, the cbegin method provides a constant iterator pointing to the start of the container.

Example 2

Let's see a simple example

Example

#include <iostream>
#include<deque>
using namespace std;
int main()
{
 deque<int> k={100,200,300,400,500};
 deque<int>::const_iterator itr;
 itr=k.cbegin()+3;
  cout<<*itr;
  return 0;
}

Output:

In this instance, the cbegin method is increased by 3, resulting in an iterator pointing to the 4th element.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience