How pointers and arrays relate

Observe array decay

In most expressions, an array converts to a pointer to its first element. The array itself and a pointer variable are still different types of objects.

int values[] = {10, 20, 30};
int *first = values;
printf("%d\n", *first);

Index through a pointer

values[i] is defined in terms of pointer arithmetic. Addition advances by elements, not bytes.

printf("%d\n", *(values + 1));  // 20

Stay inside one array

Pointer arithmetic and comparisons are defined only within the same array object, plus its one-past position. A one-past pointer may be compared but not dereferenced.

int *end = values + 3;
for (int *p = values; p != end; ++p) {
    printf("%d\n", *p);
}

Preserve the element count

Once passed to a function, an array parameter is a pointer and sizeof measures that pointer. Pass the count or use a pointer pair.