What I wish I knew before starting c programming

I started C expecting to learn a language. What I actually had to learn was a machine. That gap explains most of the frustration of the first months, and almost none of the advice I read beforehand mentioned it. Here is the short list of things I would tell myself on day one, if past me would listen.

C is small, and that is the hard part

The language itself fits on a couple of pages: a handful of types, a few control structures, functions, pointers, and not much else. I kept waiting for the rest of it to arrive, the way a larger language keeps revealing features. It does not. The difficulty is that such a small set of rules has to describe everything, so the burden shifts onto you to know what the machine will do with your code.

Once I stopped looking for missing syntax and started asking what the compiler and the memory were doing, the language got simpler and the programs got better.

The compiler is the most patient teacher you will have

For weeks I treated error messages as punishment. Then I noticed they were the only feedback that arrived instantly and never got tired. Reading the first message instead of the last, and actually looking up the words I did not understand, changed my rate of progress more than any tutorial.

Turn on warnings early. Code that compiles cleanly with warnings enabled is a different quality of code, and the habit is much easier to build at the start than to retrofit after a year.

Memory is a place, not an abstraction

I had read that a pointer holds an address and nodded along without believing it. Then I printed a pointer with %p, printed the address of a variable with &, and saw the same number in both lines. That single experiment did more than three chapters of explanation.

Draw the boxes. When a program confuses you, sketch the variables as boxes and the pointers as arrows, then check the sketch in the debugger. It feels childish for about a week and then it becomes the fastest debugging tool you own.

Type it by hand, even when you have the code

Copying working code produces a working program and no understanding. Typing it produces errors, and the errors are where the learning lives — a missing semicolon teaches you where semicolons go, a wrong header teaches you what declares what. I wish I had typed the first fifty small programs instead of pasting them.

Nobody is watching, so go slower

C has a way of punishing ambition. A program that does one thing completely is worth more than a half-finished project with three features. Smaller steps, compiled more often, finished more often — that was the whole method, and it took me an embarrassingly long time to accept it.