C is not an assembly language. So pointers are not just simple integers - pointers are special guys who know how to point to other things.
This is fundamental for how pointers and pointer arithmetic work in C, so that they can point to consecutive elements of an array. Therefore, if we write
int a[10]; int *p1 = &a[4]; int *p2 = &a[3];
then p1 - p2 will be 1. The result is 1, because the "distance" between a[3] and a[4] is one int. The result is 1, because 4 - 3 = 1. The result is not 4 (as you might think, it would be if you knew that int is 32 bits on your computer), because we are not interested in doing assembler programming or working with machine addresses; we do higher level language programming with an array, and we think in these terms.
(But, yes, at the address machine level, the method p2 - p1 calculated, as a rule, as (<value of the source address in p2 > - <value of the source address in p1 >)) / sizeof(int) .)
source share