5.1.10 · D1C Programming

Foundations — Arrays and pointers — array name decays to pointer

1,926 words9 min readBack to topic

Before you can watch "an array name decay into a pointer," you need to know what an array, a pointer, an address, a byte, *, &, [], and sizeof each actually mean — as pictures, not spells. This page builds all of them from nothing, in the order they depend on each other. Nothing here assumes you've written C before.


0. The picture everything sits on: memory as a street of numbered boxes

Figure — Arrays and pointers — array name decays to pointer

Why the topic needs this: the parent note keeps saying an array name becomes "the address of the first element." You cannot understand that until "address" means a concrete numbered box to you. Look at the figure: the small grey numbers under the boxes are addresses; the bold numbers inside are the stored bytes. They are two totally different things — a common beginner mix-up.


1. T — the type, which decides how big each box-group is

Why the topic needs this: the whole "pointer arithmetic scales by sizeof(T)" rule depends on knowing that one int is 4 boxes wide. Without a type, C wouldn't know how far to jump.


2. Array T[N] — a fixed row of N items glued together

Figure — Arrays and pointers — array name decays to pointer

Why the topic needs this: "decay" is a statement about array names. And "contiguous" is the reason arr + i can land exactly on element i — see Memory Layout and Addresses. In the figure, notice the addresses go up by 4 each time because each int is 4 bytes wide.


3. [i] — the index, counting from zero

Why the topic needs this: the parent's headline result is arr[i] == *(arr+i). Both sides use as "number of element-steps." If you thought counting started at 1, every jump would be off by one.


4. & — "address-of": ask a box for its house-number

Why the topic needs this: the definition of decay literally says the array name turns into a pointer whose value is &arr[0]. And exception #2, &arr, uses this same symbol on the whole array. Same key, two different doors — you must see & clearly first.


5. Pointer T* — a box that stores an address

Figure — Arrays and pointers — array name decays to pointer

Why the topic needs this: "array decays to pointer" means the array name is converted into exactly this arrow. See Pointer Arithmetic for how the arrow moves. In the figure, p is a small box off to the side; the orange arrow shows what it points at.


6. *p — "dereference": follow the arrow to what's there

Why the topic needs this: arr[i] is defined as *(arr + i) — you compute an address, then dereference it. Without * you'd have an address but never reach the value. & and * are a matched pair: one goes out, the other comes back.


7. sizeof — "how many bytes does this occupy?"

Why the topic needs this: sizeof is the star exception to decay — it's the one place an array name refuses to become an arrow and reports the whole 20 bytes instead of a pointer's 8. See sizeof Operator. It's also the number C uses internally to scale arr + i.


8. arr + i — pointer arithmetic, in element-steps not bytes

Figure — Arrays and pointers — array name decays to pointer

Why the topic needs this: this is the machinery behind arr[i] == *(arr+i). The figure shows why p+1 and q+1 jump different distances when p is int* (4 bytes) versus q is a pointer-to-whole-array (20 bytes) — the exact puzzle in the parent's Example 3. The jump size is decided entirely by the pointer's type, not by the number you add.


9. Putting the symbols together (a tiny sentence)


Prerequisite map

Byte = one small numbered box

Address = house-number of a box

Type T = how many bytes per item

Array T at N = row of N boxes

Index i = steps from front, from 0

Ampersand = address-of a box

Pointer T star = box holding an address

Star p = follow arrow to the value

sizeof = bytes an object occupies

Pointer plus i = scale by sizeof T

Array name decays to pointer

Read top to bottom: byte → address → pointer, and type → array → indexing, both streams feeding the topic the decay rule.


Equipment checklist

What is an address, in one phrase?
The permanent house-number of a memory box, a whole number saying where — not what's inside.
What is a byte?
One small box of memory holding a number 0–255.
What does the type T decide about a variable?
How to interpret the bits and how many bytes one item occupies (e.g. int = 4).
What does int a[5] reserve in memory?
5 contiguous int-sized slots (20 bytes), addresses rising by 4 each.
Where does C start counting array indices?
At 0, so a[0] is the first element.
What does &x give you?
The address (house-number) of the box x.
What does the * mean in the declaration int *p?
It declares p as a pointer — a box that stores the address of an int.
What does *p mean in an expression?
Follow the arrow: go to the address in p and give the value stored there.
How are & and * related?
Inverses — & turns a box into its address, * turns an address back into the box.
What does sizeof x report?
How many bytes x occupies (int=4, int[5]=20, pointer=8).
How far does p + 1 move for an int*?
4 bytes — pointer arithmetic scales by sizeof(T), not by 1 byte.
In int *p = a;, what happens to a?
It decays to &a[0], so p holds the address of the first element.