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 where
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
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 that is an address of other contents:
is a perfectly reasonable expression. Here we are using the contents at one address to “point to” contents at another address. If
is the address of the first such pair, the next pair is at
and the next after that is at
. To make this more comprehensible define
and
Then
is the address of the
pair and the
phone number is
. The list of phone numbers is
. It’s easy to screw this up (as the pedants note). If
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.