# Decode pointer arithmetic

This is a very short article about quick pointer arithmetic decoding. The basic pointer arithmetic is very easy to handle, and most of us are familiar with them. Array arithmetic is a bit tricky, but using following formula in your mind, can be easily interpreted.

in C/C++ handle pointer with an array as follows

int a = {1,2,3,4,5}

int *p = a

print a // address of a, in this case, &a
print a+1 // address of a -> &a

print *a // dereference array a
print *(a+1) // dereference array a

print p // address of &a
print p+1 // address of &a
print *(p+1) // dereference array a

Look at the following example

``````int(*a);

int b = { 1, 2, 3, 4, 5 };
int i = 0;
// Points to the whole array b
a = &b;
``````

If we print the value of *(*a+1)? Can you guess?

Now the question of, do we have any fundamental formula to apply all the cases, yes !!, we do have.

*(A+1) = A[i]
A+1 = &A[i]

Now, let's decode the above expression, *(*a+1) -> *( *(a+0) +1) -> *(A +1) -> *(A)

int B

print B = &B Using above formula, B+0 -> &B
print *B = B or &B *B -> *(B+0) -> B
print B+1 = &B1 -> &B
print *(B+1) = B & &B *(B+1) -> B

print (B+1)+2 B+2 &B *(B+1)+2 ->B+2 -> &B
print *(*B+1) = = *(&B) *(
(B+0)+1) -> (B +1) ->(&B) -> B

Likewise, all the complex pointer arithmetics are easily solvable, There are many use cases for this variation, developers should remember this variation as functions are accepting all this variation to access. It will help to read complex source codes. 