In C, array names decay into pointers pointing to their first element when passed to functions or used in arithmetic expressions. Understanding array decay and pointer arithmetic (*(arr + i)) is core to C memory management.

Pointer Arithmetic & Array Equivalence Example

array_pointer.cc
#include <stdio.h>
 
int main(void) {
    int arr[4] = {10, 20, 30, 40};
    int *ptr = arr; // Array decays to pointer to first element &arr[0]
 
    for (int i = 0; i < 4; i++) {
        // arr[i] is identical to *(ptr + i)
        printf("Index %d: Value = %d (Address: %p)\n", i, *(ptr + i), (void*)(ptr + i));
    }
 
    return 0;
}