Pointer arithmetic
p + 1 does not add 1. It adds one element — and the type decides how big that is.
Before you start
Once a pointer holds an address, you can do maths on it. p + 1 does not mean "the byte after p" — it means "the *next element*" of whatever type p points at.
That distinction is why C's arrays and pointers feel interchangeable: walking an array is really just adding 1 to a pointer, and the compiler figures out how many bytes to actually move.
This lesson steps a pointer through an array one element at a time so you can watch the address jump by 4 bytes for an int* and by 1 byte for a char* — same operation, different distance.
Stack
p holds 0x1000 — the address of arr[0], not of 'the array'.
Step 1 of 7. int *p = arr. An array name used in an expression becomes the address of its first element. So `p = arr` is the same as `p = &arr[0]`. The elements are contiguous by definition: `arr[1]` starts exactly 4 bytes after `arr[0]`, with nothing in between.
Step 01 / 07
int *p = arr
An array name used in an expression becomes the address of its first element. So p = arr is the same as p = &arr[0].
The elements are contiguous by definition: arr[1] starts exactly 4 bytes after arr[0], with nothing in between.
#include <stdio.h>int main(void) { int arr[5] = {10, 20, 30, 40, 50}; int *p = arr; p++; p += 2; printf("%td\n", p - arr); char *c = (char *)arr; c++; p = &arr[5]; return 0;}