Lesson 14 of 50 · c
Pointer Arithmetic
Duration: 10 mins
When a pointer points to an element of an array, adding or subtracting integers moves it by that many elements, not bytes.
int arr[5] = {10,20,30,40,50};
int *p = arr; // same as &arr[0]
printf("%d\n", *(p+2)); // -> 30
The compiler automatically scales the offset by sizeof(*p). Pointer arithmetic is only defined within the same array (or one past the last element).