Pointer Subtraction
The formula used by pointer substraction is:
( q - p ) == ( addr( q ) - addr( p ) ) / sizeof( T )
with T being the type of both p and q.
int array[10];
int* p1 = array + 2;
int* p2 = array + 5;
ptrdiff_t a = p2 - p1; // 3
ptrdiff_t b = p1 - p2; //...
kaustubhk.hashnode.dev1 min read