0
How does pointer arithmetic work?

Open 1 Answers 29 Views Technology
How does pointer arithmetic work?

1 Answer

0

When we increment or decrement the pointer then pointer point to the next or previous memory location. Generally, people make mistakes, when they calculate the next pointing address of the pointer.

Here is the technique to calculate the next pointing address of a pointer when applying arithmetic operation on it. To understand this technique let us consider ptr is a pointer has data type “T” and “i” is the pointer offset.

addr( ptr + i ) = addr( ptr ) + ( sizeof( T ) * i );
addr( ptr - i ) = addr( ptr ) - ( sizeof( T ) * i );
by (279k points)
...