Array Addresses and Offsets
Two ways to reach a tray
trays is an array, not a pointer variable. In most expressions, its name converts to the address of element 0. Adding 1 moves that pointer by one int element, making *(trays + 1) another way to read trays[1]. Pointer arithmetic must stay within this array or at its one-past-end position. You may form that end pointer and move back into the array, but you must not dereference it or move beyond it.
#include <stdio.h>
int main(void) {
int trays[] = {3, 5, 7};
int *cursor = trays;
printf("First: %d\n", *cursor);
cursor++;
printf("Second: %d\n", *cursor);
printf("Same element: %d\n", trays[1]);
return 0;
}
The two cursor boxes show the same pointer before and after incrementing, not two pointer variables.
The first access reads index 0; after incrementing, cursor points at index 1. The array still has three elements and cannot be assigned a new address with trays = cursor. Both lines containing 5 read element 1. If that element were 8, both lines would change together; there is still only one element there. For the exercise, you will move through four elements while keeping track of the length.