Created: 2023-01-15 12:33
Status: #concept
Subject: Programming
Tags: C Pointer Memory Address Operator

Pointer Arithmetic

Since pointers point to objects, we can easily shift between contiguous C Arrays of them using Pointer Arithmetic.

Pointer Addition Illustration.png

Boolean Operators on Pointers Illustration.png

Using Pointer Arithmetic in Array Traversal

Idiom

We have to initialize the pointer variable to the pointer of the first position of the array because we cannot modify const C Array pointers

p = &a[0]; p < &a[N]; p++

It has to loop until the max element/boundary of the array. It has to increment the pointer variable by 1, shifting its position by 1 index.

Pointer Arithmetic in Array Traversal Illustration.png

References