The pointer arithmetic is explained here ::
Pointer Arithmetic
Thank you
:::::: Some more explaination :::::::::
Pointers and integers are not interchangeable. (except for 0.) We will have to treat arithmetic between a pointer and an integer, and arithmetic between two pointers, separately.
Suppose you have a pointer to a long.
long *ptrlng;
Binary Operations between a pointer and an integer
1. ptrlng+n is valid, if n is an integer. The result is the following byte address
ptrlng + n*sizeof(long) and not ptrlng + n.
It advances the pointer by n number of longs.
2 ptrlng-n is similar.
Consider two pointers ptr1 and ptr2 which point to the same type of data.
<datatype> *ptr1, *ptr2;
Binary operations between two Pointers
1.Surprise: Adding two pointers together is not allowed!
2.ptr1 - ptr 2 is allowed, as long as they are pointing to elements of the same array.
The result is
(ptr1 - ptr2)/sizeof(datatype)
In other settings, this operation is undefined (may or may not give the correct answer).
Why all these special cases? These rules for pointer arithmetic are intended to handle addressing inside arrays correctly.
If we can subtract a pointer from another, all the relational operations can be supported!
Logical Operations on Pointers
1. ptr1 > ptr2 is the same as ptr1 - ptr2 > 0,
2. ptr1 = ptr2 is the same as ptr1 - ptr2 = 0,
3. ptr1 < ptr2 is the same as ptr1 - ptr2 < 0,
4. and so on.
Hope this helps.