12.5 POINTER ARITHMETIC
Pointer arithmetic allows us to use pointers in very interesting manner. Let a pointer point to one of the elements of an array. Now you can treat pointer like an integer and add a small constant say “n”. Please note that the result of this is a pointer pointing to nth location from the current location (where pointer is pointing). If you increment the pointer by one, it will start pointing to the next element. Pointer can also be decremented by a small constant. Its effect will be similar to addition, except the direction will be opposite. It means after p–– p will point to previous location. (p–3) will mean 3rd previous location.
Note: The pointer on its own does not know the array bounds. It is solely the responsibility ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access