When a C-style array is passed to a function or used in an expression, array gets decayed to a pointer of array element (explained in C-style array decay). When we index that array using the pointer, we use operator[] method as we usually do with arrays. But how can we do indexing on pointer? This is possible because of pointer arithmetic.
Consider the following example:
int arr[]{1, 2, 3, 4, 5};const int *ptr{arr};std::cout << ptr[1] << '\n';std::cout << *(ptr + 1) << '\n';
Both of them would print second (index 1) element of the array. Compiler converts ptr[1] to something like second form as *((ptr) + (1)) which adds one to ptr and then dereferences it to evaluate to the element.
Tip
Because compiler converts ptr[N] to *((ptr) + (N)), we could also do N[ptr] which would then converted into *((N) + (ptr)).
In first case, when we index using iptr[1], we might expect to get second element from the array but this will give fourth element from the array as pointer is relative to third element. When pointer is relative, it is better to use pointer arithmetic method to indexing.
In second case, the pointer is starting from first element so ptr[1] is more obvious that we want second element from the array. In this case, operator[] method should be followed.