Firstly, in print:
printf("\nThe address of ab is: %ld\nvalue of a is %ld\nValue of b is %ld\nsize of pointer %ld ", (&a-&c),a,b,sizeof(&a));
What you're going through is (&a-&c) , not (&a-&b) . By going through &a-&b , you really get the output:
The address of ab is: 1
Why? Probably, the compiler apparently puts a , b , c in sequential memory and looks like it's an array, and in pointer arithmetic, subtraction returns the number of elements, not bytes.
Please note that this is undefined behavior , since pointer arithmetic is only valid when they are actually in the same array, which is not in your example.
source share