C++ Standard Library C++ STL Library

C++ <cstdlib> - size_t Type



The C++ <cstdlib> size_t type is an alias of one of the fundamental unsigned integer type. This is a type able to represent the size of an object in bytes. It is the type returned by the sizeof operator and is commonly used in the standard library to represent sizes and counts.

In the <cstdlib> header file, it is defined as follows:

typedef /* implementation-defined */ size_t;              

Example:

The example below shows the usage of size_t type.

#include <iostream>
#include <cstdlib>
#include <array>
using namespace std;
 
int main (){
  //creating an array of size 10
  //and type size_t
  array<size_t, 10> arr;
    
  //populating the elements of array
  for(size_t i = 0; i < arr.size(); i++)
    arr[i] = i;

  //displaying the elements of array
  cout<<"arr contains: \n";
  for(size_t i = 0; i < arr.size(); i++)
    cout<<arr[i]<<" ";
 
  return 0;
}

The output of the above code will be:

arr contains: 
0 1 2 3 4 5 6 7 8 9 

❮ C++ <cstdlib> Library