C Programming ยท A Little Book of C

๐Ÿ“š Lesson Index

All lessons in order โ€” each one self-contained, ~15 minutes.

Lessons

  1. Lesson 1
    Where Does the Memory Come From?

    Storage must exist AND be big enough. The One Principle behind bare-pointer scanf and undersized strcat bugs.

  2. Lesson 2
    strcat, Unrolled

    The three-act structure (find end โ†’ lockstep copy โ†’ re-seal) and the two-pointer copy idiom *p++ = *q++.

  3. Lesson 3
    The const Matrix

    The three const positions around a pointer. const char *p, char * const p, const char * const p. The two-question shortcut.

  4. Lesson 4
    Unpacking *p++ = *q++

    Postfix ++ binds tighter than *. The 7-step unroll. Six forms at a glance. The classic one-liner strcpy trick.

  5. Lesson 5
    Hand-Rolled mystrcpy

    Four versions of mystrcpy: index form, expanded pointer, compact pointer, one-liner. The only difference from strcat: no Act 1.

  6. Lesson 6
    malloc, free, and the Heap

    Heap memory, malloc/calloc/realloc/free. The three heap sins. Stack vs heap decision. Hands-on: build mystrdup.

  7. Lesson 7
    Memory Errors and the Defensive Programmer

    The four heap sins in depth: leak, dangling pointer, double-free, use-after-free. Ownership rule. Valgrind and ASan. Hands-on: be a memory detective.