The Feared Chapter, Behind You

Every debt the course ran up is now paid: the & from lesson four, the copyless arrays, the failed swap, the struct copy costs, all explained by one idea, addresses as values, and two operators. What remains of C, dynamic memory, files, linked structures, is this chapter applied. The recap, and it is worth reading twice.

The Core

int *p holds an address; &x produces one; *p follows one, and writing *p writes the pointed-to variable. Pointers are typed (the dereference needs size and interpretation), initialized always (NULL or a real target, because only NULL is testable), printed with %p and a (void *) cast, and declared one per line (int *a, b; makes one pointer, the * binding to names). The model is two boxes and an arrow; draw it when confused.

Arrays Decayed

In almost every expression an array becomes a pointer to its first element: decay. a[i] is *(a + i), arithmetic moves in elements, and one-past-the-end may be formed and compared but never dereferenced, powering the p < end walk. Functions receive arrays as pointers: no copy, no &, caller elements writable, length as a separate parameter because in-function sizeof measures the pointer. Exceptions to decay: sizeof and & on the array name in its declaring scope. And 2[values] is legal, the proof indexing is sugar.

Functions Through Addresses

swap(int *a, int *b) works because the copied values are addresses and writes through them land at home: pass-by-value intact, payload changed. Out-parameters generalize it, values in, addresses out, scanf's own architecture. The two disciplines: every dereferenced pointer parameter is non-NULL by contract or checked, and no function ever returns a local's address, the stack frame dies and the pointer dangles.

Strings and Structs

char buffer[] = "text" owns writable bytes; char *p = "text" borrows the literal, and modifying a literal is undefined behaviour. p->member is (*p).member: dot for variables, arrow for pointers. Passing &record gives functions modify access at address cost, completing the rule: small read-only structs by value, everything else by address. (table + i)->member equals table[i].member.

One Program, Whole Chapter

An array passed by decay with its count, a struct modified through its address twice, the arrow doing the writing: predict the output, run it, take the quiz.

Looking Ahead

Chapter 12 leaves the terminal: files. fopen hands you a pointer to a stream, every guarded-read habit transfers intact, and programs finally remember things after they exit.