CAdvanced~4h

C: Pointers & Memory

What the standard actually promises

A broken C program does not usually announce itself. It compiles, runs, prints the number you expected, and is wrong anyway — so the judgement worth having is not "did it work" but "what was guaranteed". Six modules of unfamiliar programs, and one verdict to reach on each, with no compiler to ask.

Modules
6
Drills
12
Build steps
0
Time
~4h

Walk out able to

Read a C program that touches memory and say where each object lives, how long it lives, and whether the standard defines what happens at all.

What you judge

01

Arrows and arithmetic

Which object a write reaches, and how far an offset moves.

02

Storage and lifetime

What dates an object, and when a pointer has outlived it.

03

The heap you own

Sizing a request, and the contract every block signs.

04

Layout and the standard

Padding, members, and the four kinds of answer.

The pitch

What you practise, and what you leave with

Not an artifact — a reflex. An unfamiliar C program, a verdict on what the standard guarantees, and the line that lost it.

You will practise

  • Indirection, declarations and pointer arithmetic
  • Storage duration, and pointers that outlive
  • Sizing, freeing and the leaks between
  • Layout, legal spellings, the four answers

Afterwards you can

  • Say which object a write really reaches
  • Date any object from its declaration
  • Judge one heap block from malloc to free
  • Sort a program into the standard’s four

Modules

6 modules, 27 items

Lessons explain one idea. Drills repeat it until it sticks. Build steps make something that exists afterwards.

  1. 1

    Follow the arrow

    ~39 min

    Name the object a write through a pointer reaches, and read a declaration cold.

    • LessonSay where the write lands8 min
    • LessonReach a caller’s pointer6 min
    • LessonTell null from uninitialised6 min
    • DrillSay which object changed10 min
    • DrillRead a declaration inside out9 min
  2. 2

    Walk the array

    ~40 min

    Scale an offset by its pointee and say exactly where a pointer into an array may sit.

    • LessonFence the legal addresses7 min
    • LessonSay why there is no step below6 min
    • LessonWatch a bounds check disappear6 min
    • DrillScale the offset yourself11 min
    • DrillTell an array from a pointer10 min
  3. 3

    Where it lives, how long

    ~31 min

    Name any object’s storage duration and say whether a pointer to it has outlived it.

    • LessonDate the object, not the address7 min
    • LessonFind the brace that ends it6 min
    • LessonDrop the map, keep the duration6 min
    • DrillCall the pointer valid or dangling12 min
  4. 4

    Own the allocation

    ~41 min

    Size a request from its pointee, and judge one block against the free contract.

    • DrillCount the bytes you asked for10 min
    • LessonState the contract every block signs7 min
    • LessonGrow a block without losing it6 min
    • LessonNull it, and know what that buys6 min
    • DrillJudge one block, end to end12 min
  5. 5

    Read the struct, read the line

    ~31 min

    Compute a struct’s size, reach any member, and name the line a compiler must reject.

    • DrillPlace the members and round the total12 min
    • DrillSay what the operators bound to9 min
    • DrillName the line that is rejected10 min
  6. 6

    What the standard does not promise

    ~46 min

    Put a program in one of the standard’s four categories, and find the line that lost it.

    • LessonTell the four answers apart7 min
    • LessonUndefined is not a runtime event6 min
    • LessonSort a program in two questions6 min
    • DrillPut it in one of the four13 min
    • DrillFind the line that loses it14 min

It compiled. It ran. Is it correct?

The first item is free. ~4h of focused work, at your own pace.

Advanced~4h6 modules