Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ array::size function is used to find out the total number of elements in the array. It returns the total number of elements held in the array, and it is not necessarily equal to its storage capacity.

Syntax

size_type size() const noexcept;

Parameters

No parameter is required.

Return Value

Number of elements present in the array.

Time Complexity

Constant i.e, Θ(1).

Example:

In the below example, the array::size function is used to find out the total number of elements in a array called MyArray.

#include <iostream>
#include <array>
using namespace std;
 
int main (){
  array<int, 100> MyArray;

  cout<<"Array size is: "<<MyArray.size()<<"\n\n";
  return 0;
}

The output of the above code will be:

Array size is: 100

❮ C++ - Array