Quiz Entry - updated: 2026.07.10
How does pointer arithmetic work in C?
Adding n to a pointer advances it by n × sizeof(*p) bytes, not n bytes — so p + 1 always lands on the next element regardless of element size.
* a++ advances by sizeof(int) = 4 bytes, so the pointer walks 20, 24, 28 … up to the one-past-end marker ep. *
int A[10];
// Points to A[0] at address 20
int *a = A;
// Points past A[9] at address 60 (one-past-end)
int *ep = A + 10;
Memory layout (assuming 4-byte ints):
A[0] A[1] A[2] ... A[9]
20 24 28 ... 56 60 ← ep (one past end)
↑
a
Pointer increment:
// Moves to next int (adds 4 bytes, not 1!)
a++;
// a was 20, now it's 24
// Iteration with pointers:
while (a < ep) {
// Print and advance
printf("%d", *a++);
}
The formula:
// These are equivalent:
A[i]
*(A + i)
*(i + A)
// Yes, this works! (but don't use it)
i[A]
Key insight: a + 1 doesn't add 1 to the address - it adds sizeof(*a) to the address.
Go deeper:
Pointer (computer programming) — Wikipedia — pointer arithmetic and the
a[i]≡*(a+i)equivalence.