DEQUE CBEGIN() in C++


Given the task is to show the working of deque::cbegin() in C++ STL.

What is Deque::cbegin( ) function?

deque::cbegin() is a function which comes under deque header file, cbegin() returns the iterator pointer which points to the first element of the deque container.

Note − cbegin() function does not have any arguments in it.

Syntax

deq.cbegin();

Where deq is the deque’s object.

Return Value

The function returns a const_iterator.

const_iterator is a random access iterator which is used to point to the first element of the deque container. We can traverse the whole container using the first element of the container, but this can’t be used to do the modifications in the container’s value, but can print the whole container.

Example

 Live Demo

#include <deque>
#include <iostream>
using namespace std;
int main(){
   deque<int> dqe = { 65, 2, 31, 5, 9 }; // creation of deque
   cout<<"First element of the deque is: ";
   cout<<*dqe.cbegin(); // returns first element of deque
}

Output

If we run the above code it will generate the following output −

First element of the deque is: 65

Explanation

In this code, 1st of all, the header file contains all the functions of the deque. we have a tendency to declare the deque having some values in it. Then, we have a tendency to print the primary component of the deque exploitation the perform cbegin( ), wherever cbegin( ) is employed to return the primary component of the list.

Updated on: 30-Jan-2020

85 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements