5.1.8 · D1C Programming

Foundations — Pointers — declaration, dereferencing ( - ), address-of (&)

1,799 words8 min readBack to topic

This page assumes nothing. Before you touch [[Pointers — declaration, dereferencing ( - ), address-of (&)|the parent note]], we build every symbol it uses — the variable, the byte, the address, the two operators & and *, the type tag, and NULL — one on top of the last. If a symbol appears in the parent, it is earned here first.


0. The picture underneath everything: memory as a street

Look at the figure. The street runs left to right. Every house is one byte. The number under each house is its address — it never changes. The stuff inside a house is its contents — that can change.

Figure — Pointers — declaration, dereferencing ( - ), address-of (&)

1. Symbol: a variable (a named house)

The name x is a convenience for you. The machine only knows the address. So a variable is really a (name, address, value) bundle — and the address is the part beginners never see, yet it is the whole game.

Figure — Pointers — declaration, dereferencing ( - ), address-of (&)

2. Symbol: a type (the size + meaning tag)

WHY the topic needs this: an address alone (say 0x1000) is not enough to read a value — it only says where to start. You also need to know how many bytes to grab and how to interpret them. That is exactly the extra information a pointer's type carries, and it is why int * and char * are different even though both hold "just a number".


3. Symbol: & — the address-of operator (ask a house its number)

WHY a whole operator for this: without &, you could never obtain an address to store or pass along. & is the only door from the world of names into the world of addresses.

Figure — Pointers — declaration, dereferencing ( - ), address-of (&)

Look at the red arrow in the figure: it starts at the name x and points down to its address number. That downward "what's your house number?" motion is precisely &.


4. Symbol: a pointer variable and the * in a declaration

Now we have addresses (numbers). Where do we keep one? In a variable — but a special variable that promises "the number I hold is an address, and it points at an int".


5. Symbol: * — the dereference operator (walk to the house and look inside)

WHY we need it: & got us the address; without * an address would be a dead number we could never use. * is the return trip — from a house-number back to the stuff inside that house.

Figure — Pointers — declaration, dereferencing ( - ), address-of (&)

Trace the figure: p holds the number 0x1000 (top box). The red arrow jumps from p to the house at 0x1000 and reads 42. That jump is *p.


6. Symbol: NULL (the address that points nowhere)

WHY the topic needs it: a pointer that was never aimed anywhere holds garbage — a random number that may name a forbidden house. NULL gives you a safe, checkable "empty" value so you can guard if (p != NULL) ... before travelling.


7. How the pieces connect

Byte: one storage box

Memory: street of bytes

Address: the box number

Variable: named box at an address

Type: bytes plus meaning

Address-of & gives the number

Pointer: box that stores an address

Dereference * follows it to the value

Inverse identity star of amp x equals x

NULL: the point-nowhere value

Pointers topic: pass address to change caller data

Read it upward from the bottom: the parent topic stands on the inverse identity, on NULL, and on dereferencing — each of which rests on the pointer box, which rests on address + type, which rest on the byte-street. No layer is skipped.


Equipment checklist

Test yourself — say the answer out loud before revealing.

What is a byte, in one phrase?
The smallest addressable storage box in memory, holding a number 0–255.
What is an address?
A whole number that names which box in memory you mean — like a house number.
A variable is really a bundle of which three things?
A name, an address (where it lives), and a value (what it currently holds).
What two facts does a type tell the compiler?
How many bytes one value takes, and how to interpret those bytes.
What question does &x ask, and what does it return?
"What is the address of x?" — it returns a number (the location), not the value.
In int *p;, what job does the * do?
It is part of the type — it declares p as a pointer to int; it is NOT the "go fetch" action.
In the expression *p, what does * do?
Follows the address stored in p to its house and reads (or writes) the value there.
Why is *(&x) equal to x?
& goes name→address, * goes address→value; done in sequence they cancel — a round trip back to x.
What is NULL and why never dereference it?
The "points nowhere" value (address 0); dereferencing it walks to a forbidden house and crashes.