Question: ```
short x = 5;        
short*ptr = &x;     
short *ptr2 = ptr+5; 

cout << ptr2 - ptr << endl;
cout << (long) ptr2 - (long)ptr << endl;

```

I understand that pointers store addresses, but I don't understand why the answer for both lines isn't 10.

Isn't ptr2 = address of pointer + sizeof(short) \* 5?

Answer: 
The *memory* addresses may be ten bytes apart but that's not how pointer addition/subtraction works. The values used are *scaled* based on the size of the data type so, for a two-byte `short`, values will be half of what you would expect from the actual memory addresses (if your data type was the one byte `char`, it would work as you seem to expect).

It's really no different to a `pointer + 4` addition which gives you the address of the fifth element in the array, *not* the address five bytes befond the pointer.

This is covered in the `[expr.add]` section of the standard (text from `C++17`):

> 
> When two pointers to elements of the same array object are subtracted, the type of the result is an implementation-defined signed integral type; this type shall be the same type that is defined as `std::ptrdiff_t` in the `<cstddef>` header (21.2).
> 
> 
> If the expressions `P` and `Q` point to, respectively, elements `x[i]` and `x[j]` of the same array object `x`, the expression `P - Q` ***has the value `i − j`;*** otherwise, the behavior is undefined.
> 
> 
> 

---

Of course, this is a moot point in your case anyway since, as per that quote, what your are doing is undefined behaviour. Pointer subtraction is not defined unless both pointers are within the same array (or one byte beyond said array).
Pointer arithmetic does behave algebraically.

if y = x + 5, then y - x = 5. This is true if x and y are integers, or x and y are pointers to the same type.

Note that you can not do z = y + x with pointers. z does NOT equal 2x + 5. It does not even compile. You cannot add two pointers, but you can take the difference between two pointers (and get the count of elements).