English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Usage and example of deque size()

C++ Deque (Double-ended Queue)

C ++ The deque size() function returns the number of elements in the deque.

For example:

deque<int> d={1,2,3,4,5};
                        d.size() =5;

Syntax

return_type size();

Where, return_type is an unsigned integer type.

Parameters

It does not contain any parameters.

Return value

It returns the number of elements in the deque container.

Example

Let's look at a simple example

#include <iostream>
#include<deque>
using namespace std;
int main()
{
  deque<int> d;
  cout << "The size of the deque is: " << d.size();
  cout << '\n';
  d.push_back(1);
  d.push_back(2);
  d.push_back(3);
  cout << "The size of the deque is: " << d.size();
   return 0;
}

Output:

The size of the deque is: 0
The size of the deque is3

In this example, when the deque 'd' is empty, the size() function will return 0. When three elements are added to the deque container, the size() function will return3.

C++ Deque (Double-ended Queue)