Skip to content
Codescope

Pointer arithmetic

p + 1 does not add 1. It adds one element — and the type decides how big that is.

core10 min7 steps

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

main()
arr[0]
10
0x1000
arr[1]
20
0x1004
arr[2]
30
0x1008
arr[3]
40
0x100c
arr[4]
50
0x1010
pint *
0x1000
0x1020

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.

01 / 07

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.

pointer-arithmetic.cC
#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;}