Nearby lessons
92 of 124C - Pointer Arithmetics
Learn pointer arithmetic in C — adding to a pointer moves it forward by the size of the type it points to, which is how you walk through arrays with a pointer.
What is Pointer Arithmetic?
You can add integers to a pointer. p + 1 does not move 1 byte — it moves forward by the size of the type the pointer points to. For an int pointer that is sizeof(int) bytes, so p + 1 lands exactly on the next integer.
In simple words: pointer arithmetic follows the type size — p + 1 on an int pointer skips 4 bytes (one whole int), not 1 byte.
Walking an Array with a Pointer
Because the array name is the address of the first element, *(p + i) reaches element i — exactly like a[i]:
Example02
Pointer Increment (p++)
You can also move a pointer forward step by step with p++ inside a loop:
Example03
Rules to Remember
- Adding to a pointer moves by the size of the pointed-to type.
*(p + i)andp[i]mean the same thing.- Pointer subtraction tells how many elements are between two addresses.
- Do not add two pointers — that is meaningless.
📝 Key Takeaways
- p + 1 on an int pointer moves by sizeof(int) bytes
- *(p + i) reaches the element at index i
- Pointer arithmetic is how arrays are traversed internally
🧠 Test Your Knowledge
2 QuestionsProgress: 0 / 2