# Pointers draft

Despite pedants, pointers are useful and interesting and if you don’t understand them, you don’t really get what’s going on in a computer. Think of memory as a function $M: Nto N$ where $N$ is the set of non-negative integers. When we build physical memories, there are limits on both domain and range, but let’s ignore that for now. We can call the elements of the domain “addresses” and the elements of the range “contents”, but  they are both just non-negative integers.   A list of numbers, maybe phone numbers, could be in memory as a sequence. Perhaps $M(x_0), M(x_0 +1) dots M(x_0 +k)$ is the list.

 x0 2125551212 x0+1 3015551212 x0+2 7125551212 … x0+k 5125551212

Alternatively, that data could be scattered around memory in pairs of phone number and address of next phone number. Address and contents are just numbers. The memory may have contents $M(x_0)$ that is an address of other contents: $M(M(x_0))$ is a perfectly reasonable expression. Here we are using the contents at one address to “point to” contents at another address. If $y_0$ is the address of the first such pair, the next pair is at $y_1 = M(y_0 +1)$ and the next after that is at $y_2 = M(y_1 +1)$. To make this more comprehensible define $Y(0) = y_0$ and $Y(n+1) = M(Y(n) +1)$ Then $Y(i)$ is the address of the $i^{th}$ pair and the $i^{th}$ phone number is $M(Y(i))$. The list of phone numbers is $M(Y(0)),dots M(Y(k))$. It’s easy to screw this up (as the pedants note). If $M(Y(i)+1)$ is not the right address of the next element, following the chain could end up making a random tour of memory that would pull up who-knows-what as phone numbers.