You are evaluating the difference, or "distance" between two pointers to int
. sizeof(int)
is 4 on your platform. The difference between 60 and 20 is 40, which is the distance between 10 ints. Your implementation seems to be simply evaluating this difference.
However, the C standard places a restriction on the evaluation of the difference between two pointers: both pointers must point to elements in an array, or one past the end. If you can ensure both i
and j
satisfy this, then the difference evaluation is valid. Since your code does not necessarily satisfy that condition, it may have undefined behaviour, in which case the output/outcome could have been anything.
Also note that is is undefined behaviour to de-reference i
and j
unless they point to valid addresses holding int
values.