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

Deque Size Function

BLUF: Mastering Deque Size 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 Size Function

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

C++ Deque size

The size function in C++ Deque calculates the quantity of elements stored within the deque container.

For example:

Example

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

Syntax

Example

return_type size();

where , return_type is an unsigned integral type.

Parameter

It does not contain any parameter.

Return value

It provides the count of elements present in the deque container.

Example

Let's see a simple example

Example

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

Output:

Output

size of deque is :0
size of deque is :3

In this scenario, if the deque 'd' is devoid of elements, the size method will yield a result of 0. However, upon adding three elements to the deque container, invoking the size function will result in a value of 3.

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