Five phases, roughly ninety to a hundred and twenty hours. C is a small language and a long apprenticeship: the syntax takes a fortnight and the memory model takes months, because the memory model is the part that other languages were invented to hide from you.
Compile with the warnings on, from the first file.
gcc -Wall -Wextra -g -std=c17 main.c -o main
C's defaults are permissive for reasons that are forty years old. Most of what -Wall -Wextra reports is a real bug, and the single biggest difference between somebody learning C well and somebody learning it badly is whether they read those messages or scroll past them. From phase four, add the sanitisers:
gcc -fsanitize=address,undefined -g main.c -o main
valgrind --leak-check=full ./main
These find use-after-free, buffer overruns, leaks and undefined behaviour at the moment they happen, with a line number. Finding any of them by reading the code is guesswork, and the bug that reads correctly is the one that will cost you a weekend.
Build the four projects. They are the course.
Reading about pointers produces a feeling of understanding that disappears the moment you need one. Each project is chosen for what it forces.
| Stage | Project | What it forces |
|---|---|---|
| Beginner | CLI calculator, or a guessing game | Loops, conditionals, scanf/printf, functions |
| Intermediate | Tic-tac-toe, or a matrix library | 2D arrays, pointers, modular functions |
| Upper-intermediate | Contact or student record manager | struct, dynamic memory, binary file I/O |
| Advanced | A shell, or your own allocator | System calls, string parsing, pointer arithmetic, heap management |
Build the beginner one during phase two, the intermediate during phase three, the record manager during phase four, and the shell or allocator as the capstone. Writing an allocator in particular teaches more about malloc than any amount of reading, because you have to decide what the metadata looks like and where it lives.
Pacing
Phase 1, one to two weeks. If you have programmed before, most of this is translation. Do not skip the compilation stages: knowing which of the four failed is what makes the error messages legible for the rest of your life.
Phase 2, two weeks. Mostly familiar. The parts that are not are the storage classes and the two meanings of static.
Phase 3, three to four weeks, and do not hurry it. This is the phase. If pointers are not comfortable, nothing after this will be, and the symptom of rushing it is phase four feeling arbitrary. Draw the memory. Boxes with addresses in them, arrows between them - on paper. Everyone who is good at C has done this, and most of them still do it when a bug is strange enough.
Phase 4, three weeks. Where C stops being a syntax and becomes a model of the machine. Run everything under the sanitisers from here on.
Phase 5, three to four weeks. The systems work, and the capstone. Implement the data structures from scratch even though you know the algorithms, because the algorithm is not the lesson - the pointer handling is.
Three habits
Initialise every pointer to NULL, and set it back to NULL after free. It converts the two worst bug classes in C - use-after-free and double-free - into a clean crash at the right line.
Check every allocation and every fopen. Unchecked code works on your laptop for years and fails on the machine that matters.
Draw the memory when you are stuck. Not a metaphor. An actual diagram.
A note on the standard and on advice you will find
Use C17 or C11 - -std=c17 - rather than whatever your compiler defaults to. A great deal of C advice online is from the 1990s and tells you to use gets (removed from the language, for being impossible to use safely), to cast the result of malloc (unnecessary in C, and it can hide a missing header), or to avoid declaring variables anywhere but the top of a block (a C89 restriction that has not applied since 1999).
On undefined behaviour
C has a category of program that is not wrong in the way a syntax error is wrong - it is a program the standard declines to describe at all. Signed overflow, reading uninitialised memory, dereferencing NULL, indexing past an array. The compiler is permitted to assume you never do these things, and it optimises on that assumption, which is why undefined behaviour often does not look like a crash. It looks like a check that was deleted. The article attached to this course works through exactly that, and it is worth reading before phase four rather than after.