Example 1 — Read, update, and pointer form
Two spellings access the same element.
#include <stdio.h>
int main(void) {
int arr[] = {10, 20, 30, 40};
int n = sizeof arr / sizeof arr[0];
printf("first = %d, last = %d\n", arr[0], arr[n - 1]);
arr[1] = 25;
printf("arr[1] = %d\n", arr[1]);
printf("*(arr + 2) = %d\n", *(arr + 2));
return 0;
} How It Works
arr[n - 1]is the last element without hard-coding 3.- Assigning
arr[1] = 25overwrites the old 20. *(arr + 2)moves two elements forward and dereferences.
