We can use pointer arithmetic to traverse a C-style array as shown in following example:

#include <iostream>
 
int main(int argc, char const *argv[])
{
    constexpr int arr[]{2, 1, 5, 3, 9};
    
    const int *begin{arr};
    const int *end{arr + std::size(arr)};
 
    for (; begin != end; ++begin)
    {
        std::cout << *begin << '\n';
    }
 
    return 0;
}

The main parts are beginand end pointers which contains address of starting element and post one address of last element. We increment begin until it reaches the end. In loop, we dereference the pointer to get the element.

This begin and end mechanism is what range based for loop uses.

References

  1. https://www.learncpp.com/cpp-tutorial/pointer-arithmetic-and-subscripting/
  2. https://en.cppreference.com/w/cpp/language/range-for