Consider the following code:
char* p = new char[2]; long* pi = (long*) p; assert(p == pi); // OK char* p1 = &p[1]; long* pi1 = (long*) p1; asser
Its doing integer (long) pointer arithmetic for pi1 - pi;
pi1 - pi
If p1 were &p[4] you'll see that it prints 1 for d1 while the difference is actually 4 bytes. This is because sizeof (long) = 4 bytes.
p1
&p[4]
1
d1
sizeof (long)