If you’re learning C to program a microcontroller, the first few examples can make the language feel straightforward. A loop is a loop. Then a driver hands you a pointer to a buffer. Can you change the first reading? What happens if you move the pointer? Can you keep it after the function returns? For me, that’s where learning C gets interesting, and where the right book makes a difference.

If that buffer is what brought you here, start with Kenneth Reek’s Pointers on C. If your program works in the board vendor’s IDE and you want to know what the Build button did, I’d start with Brian Gough instead. I recommend four books in the video because I reach for them at different moments. When that C program has to read a file on a Raspberry Pi, I reach for Michael Kerrisk’s The Linux Programming Interface. When sensor readings arrive faster than I can process them, I reach for Noel Kalicharan’s Data Structures in C. Those are the two books I’d add after the original four.

Watch the original video: Top 4 Recommended Books to Learn C. Here we’ll use the same four books to build one little program. You can run it on a computer with GCC and GNU Make. No board or sensor required.

1. An Introduction to GCC — follow the build

An Introduction to GCC is by Brian Gough, with a foreword by Richard M. Stallman. It’s the one I pick up when I want to understand what the Build button did. Start with the part on compiling multiple source files. It answers a surprisingly useful question: what can GCC do with just half a program? Read the book.

What happens to a line of C before you can run it?

Suppose I write #define LIMIT 25, then compare a reading with LIMIT. The preprocessor expands the macro to 25 and brings in the declarations from my headers. The compiler translates the resulting C into assembly for the target. The assembler encodes those instructions in an object file. Finally the linker connects references across the object files and the libraries the program needs.

Four build stages from macro expansion through linking.
The useful debugging question is which stage last succeeded.

You can stop the build at each of those boundaries. In the example below, try gcc -E main.c -o main.i and search the result for count_above. Next run gcc -S main.c -o main.s and look for the call on your target. Now you have a way to investigate a complaint about a missing header separately from a complaint about a missing function.

This is also why I think Gough is worth reading if you eventually move to Rust. A native Rust program still has to become instructions for your processor, and its build commonly ends with a linker. Rust handles macros and earlier compilation stages differently. The habit that carries over is asking what artifact the tool produced and what the next tool still needs.

Imagine four temperature readings. We want to count how many are strictly above 25. Create these three files in an empty directory. The header is a promise about how to call the function. One source file keeps the promise. The other uses it.

readings.h · Declare the interface

readings.hc
#ifndef READINGS_H
#define READINGS_H

#include <stddef.h>

size_t count_above(const int *samples, size_t count, int limit);

#endif

readings.c · Define the function

readings.cc
#include "readings.h"

size_t count_above(const int *samples, size_t count, int limit)
{
    size_t hits = 0;
    for (size_t i = 0; i < count; ++i) {
        if (samples[i] > limit) {
            ++hits;
        }
    }
    return hits;
}

main.c · Call it with four readings

main.cc
#include <stdio.h>
#include "readings.h"

int main(void)
{
    const int samples[] = {18, 25, 31, 28};
    size_t count = sizeof samples / sizeof samples[0];
    printf("%zu readings above 25\n", count_above(samples, count, 25));
    return 0;
}

Build the pieces separately so you can see where one job ends and the next begins.

Compile, link and runbash
gcc -std=c17 -Wall -Wextra -Wpedantic -c main.c -o main.o
gcc -std=c17 -Wall -Wextra -Wpedantic -c readings.c -o readings.o
gcc main.o readings.o -o readings
./readings

You should see 2 readings above 25. At the end of the first command, main.o contains a compiled call to count_above. It can exist before the linker has found the definition. Try gcc main.o -o incomplete on its own. The missing definition is why that command fails. By contrast, a misspelling in #include "readings.h" stops the build before you even have a new object file. Those two messages send me looking in different places.

2. The C Programming Language — learn to read a declaration

Brian W. Kernighan and Dennis M. Ritchie pack a lot into a small book. I get more out of K&R with a program open beside it. If you’re new, start with the introductory examples, then use the functions and pointers chapters when a line in your own program needs explaining. The second edition describes ANSI C. It’s a useful reference for the fundamentals even though later standards added features. Kernighan’s page for the second edition.

Read the declaration in readings.h aloud. The function returns a count. It accepts a pointer to integers it can read, a number of elements and a threshold. There is no information in const int *samples that says “four readings.” That is why the caller passes count.

My exercise here is one character long. Before you run anything, predict what changing > to >= does. The answer goes from two to three because exactly one reading equals 25. The return type, the loop bound and the pointer stay the same. Restore the original comparison for the remaining examples.

Try it: test the boundary at 25

Back in our small readings program, the caller passes two things: where to start reading and how many readings to use. With {18, 25, 31, 28} and a threshold of 25, the whole batch has two readings above the threshold. Ask for just the first two and the answer is zero: 18 is below and 25 is equal. Start two positions later and the answer is two: both 31 and 28 qualify. Save this as test_readings.c to check those cases and an empty batch.

test_readings.cc
#include <assert.h>
#include "readings.h"

int main(void)
{
    const int samples[] = {18, 25, 31, 28};
    assert(count_above(samples, 4, 25) == 2);
    assert(count_above(samples, 2, 25) == 0);
    assert(count_above(samples + 2, 2, 25) == 2);
    assert(count_above(samples, 0, 25) == 0);
    return 0;
}
Run the checksbash
gcc -std=c17 -Wall -Wextra -Wpedantic -g -fsanitize=address,undefined test_readings.c readings.c -o test_readings
./test_readings

Run this on your development machine with a GCC build that includes the sanitizers. A passing run is silent. The assertions check our answers. AddressSanitizer and UndefinedBehaviorSanitizer look for certain execution errors along the paths we exercised. Now change > to >=, predict which assertion will fail first, and rerun. Restore the comparison afterward. The first assertion now fails: counting 25 gives three matches instead of two.

3. Pointers on C — draw the four cells

Kenneth Reek’s Pointers on C is the book I recommend when pointer syntax looks familiar but you still can’t picture what a line does. What helped me were the drawings. A box for an object and an arrow to that box can explain more than another reading of the same declaration. Publisher’s book page.

Pointer arithmetictext
index         0      1      2      3
value       [18]   [25]   [31]   [28]
             ↑             ↑
          samples      samples + 2

If I copy a pointer, do I copy the integer?

Here’s how I use the drawing idea from Reek. Take int score = 7; and int *p = &score;. On paper, give score a box containing 7. Give p a separate box containing the address of score. When you read *p, put your pencil on the pointer and follow the arrow. You reach 7.

Now add int *q = p;. How many boxes contain the integer 7? Still one. The assignment copied the address. Write *q = 9; and you can predict exactly what changes in the picture. The box for score now contains 9. Reading *p gives 9 too.

Two pointer variables point to the same score; writing through q changes what p reads.
My sketch of an alias: two ways to reach one live integer.

One more example, because this is the pair of operations I’d want to tell apart before touching a sensor buffer. Put 18, 25, 31, 28 in a writable array and point p at 18. With ++p, move the arrow one cell to the right; all four numbers stay put. With ++(*p) at that new position, keep the arrow still and change 25 to 26. These exercises are why I recommend Reek so strongly. I can cover up the answer, draw the change, and check whether I actually understood the expression.

Inside the function, samples + 2 points to the third integer. *(samples + 2) reads 31. Adding two advances by two elements, regardless of how many bytes an integer occupies on that machine. You can form a pointer just past the fourth element as a stopping point. Reading through that pointer is outside the array.

Try replacing samples[i] with *(samples + i). Predict the output. Then look at the count calculation in main. There, sizeof samples measures the whole array. Move that calculation into count_above and the name refers to a pointer parameter. Now you’re measuring the pointer. Drawing the caller’s array and the callee’s pointer separately makes that mistake much easier to spot.

Want to move the pointer yourself? How Pointers Work in C follows these four readings through a double pointer, then opens the memory dump so you can see the bytes.

4. The GNU Make Manual — what happens when I press Build?

When I’m learning C, I can compile the first example with one GCC command. The moment I split that program into main.c, readings.c and a shared header, I have a new question. If I change one file, which commands do I need to run again? That’s why a book about Make made my list of C books. Knowing the language helps me write a function. Knowing my build helps me get the version of that function I just wrote into the executable I’m about to test.

Say I change how the average is calculated inside readings.c. I can reuse main.o. I need to compile readings.c again and link the two objects. Now suppose I change the function declaration in readings.h. Both source files include that header. I want GCC to check the caller and the implementation against the new declaration. If my handwritten build forgets the header dependency, I can end up testing an executable assembled from objects built against different versions of that interface.

This is the part of the manual I’d read first. A target is the file I want to build. Its prerequisites are the files it depends on. A recipe is the command Make runs when the target is missing or older than a prerequisite. Read readings: main.o readings.o as “to build readings, I need both object files.” The indented line underneath tells GCC how to link them. Start it with a tab when you type the example. GNU Make Manual, An Introduction to Makefiles.

Save this as Makefile beside the three files. The last line adds the shared header as a prerequisite of both objects. GNU Make supplies the ordinary .c-to-.o compile recipe through its built-in rule.

Makefilemakefile
CC = gcc
CFLAGS = -std=c17 -Wall -Wextra -Wpedantic

readings: main.o readings.o
	$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)

main.o readings.o: readings.h

In the link recipe, $@ is the target (readings) and $^ expands to the two object files. Try these three builds and watch the commands in your terminal.

  1. Run make from a clean directory containing the sources and Makefile. You’ll see two compile commands and one link command. Run it again immediately and everything is up to date.
  2. Run touch readings.c, then make. You’ll see one compile and one link. Make reuses main.o.
  3. Run touch readings.h, then make. Both compile commands return, followed by the link. Touching the file changes its timestamp, so you can test the dependency without changing any C code.

I keep the manual around for the day an embedded project builds in the IDE and I need to reproduce it from a terminal. If the project uses Make, make -n shows the commands it plans to run for an ordinary build like this one. I can see which compiler it picked and which flags it passed. A missing header sends me looking at the include path on the compile line. An undefined reference sends me looking for the object or library on the link line. That’s what I want from this book: enough understanding to know where to look when pressing Build stops working.

Three references I’d reach for later

Noel Kalicharan’s Data Structures in C: learning to implement a data structure

In Python, if I want a stack, I can start with a list. I call append(31) to put a value on top and pop() to get it back. Someone has already written the code that manages the storage. What I like about learning this in C is that I get to write that part myself. The C standard library gives me no general-purpose stack or queue. I have to decide how to represent one and what its operations actually do.

Take four sensor readings. Suppose I want the most recent one back first. An array with room for four integers and a count is enough to build that stack. If it holds 18 and 25, the count is two. To push 31, write it into slot two and increase the count to three. To pop, bring the count back to two and read slot two. The caller gets 31. Its old bits can stay in the array; the count tells me which entries still belong to the stack.

Here’s the implementation I’d start with on a small board. A fixed capacity keeps the storage predictable. I’ve chosen to return false when a push would overflow or a pop would read an empty stack. That decision is part of the interface too.

A four-entry stackC
#include <stdbool.h>
#include <stddef.h>

enum { CAPACITY = 4 };
struct stack {
    int values[CAPACITY];
    size_t count;
};

bool push(struct stack *s, int value)
{
    if (s->count == CAPACITY) return false;
    s->values[s->count++] = value;
    return true;
}

bool pop(struct stack *s, int *out)
{
    if (s->count == 0) return false;
    *out = s->values[--s->count];
    return true;
}

Start with struct stack s = {0};. The caller can now use push(&s, 31) and pop(&s, &reading), where reading is an int, and check each return value. That’s the abstraction I wanted: the caller asks for an operation, and the implementation takes care of indexing and bounds.

Now change the requirement. If I need to write every reading to a file in arrival order, a stack gives me the newest reading first. I want a queue for that job. I could keep the same four slots and track where to read and write next, or build a linked queue and take responsibility for allocating and releasing its nodes. This is where I reach for Kalicharan. I’ve used it as a reference rather than reading it cover to cover. Seeing how lists, queues and trees are built in C helps me understand what I’m asking a collection to do, even when I go back to a language that supplies it. Data Structures in C by Noel Kalicharan.

The Linux Command Line. William Shotts’ book is useful alongside the GCC exercises. Start by finding your working directory, listing the files and running a program by path. Understanding the dot in ./readings is a small win that carries straight into embedded Linux work. Author’s free edition.

Michael Kerrisk’s The Linux Programming Interface: when C meets the OS

On a Raspberry Pi, the interesting part often starts after the sensor code works. Now I want a program that opens yesterday’s readings, processes them, and writes a result. Where is the file position kept? What happens if I ask for 100 bytes and only 17 come back? These are questions about Linux, and a C syntax reference won’t tell me what the operating system promises.

Kerrisk starts with a model you can use immediately. open() gives the process a file descriptor on success. Pass it to read(). For a regular file, a positive result tells you how many bytes you actually got, zero after a nonzero request means end of file, and −1 means an error to inspect. Process those 17 bytes, then ask again. Close the descriptor when you’re done.

The reason I keep this big book around is that the file example leads somewhere. If I put the reader in one process and the writer in another, a pipe gives them a stream to share. If I use two threads in one process instead, they can see the same buffer and I have to decide who can change it. C is a particularly direct way to learn these long-established UNIX interfaces, and the underlying questions still matter when another language wraps them. Start with Kerrisk’s free file I/O chapter and come back for process creation when you have a use for it. The Linux Programming Interface and sample chapters.

Try it: who remembers where the next read starts?

Imagine two temperature readings in a little text file: 18 and 25. Write the four characters 1825, with no separator, so we can track every byte by eye. Open the file and duplicate the descriptor. If I read two bytes through each descriptor, do I get 18 twice?

This is where Kerrisk’s explanation is worth the shelf space. My program holds two small integers. Linux holds an open file description with the current file position. Both integers refer to that same description. Reading through the first descriptor advances the position that the second descriptor will use.

Two file descriptors point to one open file description. Its byte offset moves from zero to two to four.
Two handles in the process, one position for this open file.
offset.c · predict the second readc
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>

static int show_two(int fd, const char *label)
{
    char buf[2];
    ssize_t n = read(fd, buf, sizeof buf);
    if (n < 0) { perror("read"); return 1; }
    printf("%s: %.*s (%zd bytes)\n", label, (int)n, buf, n);
    return 0;
}

int main(void)
{
    int first = open("readings.txt", O_RDONLY);
    if (first < 0) { perror("open"); return 1; }
    int second = dup(first);
    if (second < 0) { perror("dup"); close(first); return 1; }
    int failed = show_two(first, "original");
    if (!failed) failed = show_two(second, "duplicate");
    close(second);
    close(first);
    return failed;
}
Run in an empty directorybash
printf '1825' > readings.txt
cc -std=c17 -Wall -Wextra offset.c -o offset
./offset

The first line says original: 18 (2 bytes). The next says duplicate: 25 (2 bytes). Change the file to 182 and run it again. The duplicate now reads just 2, one byte. With only 18 in the file, the duplicate reads zero bytes. Asking for two bytes sets a maximum; the return value tells you how much data is yours to process.

Now replace dup(first) with another open("readings.txt", O_RDONLY), restore 1825, and rebuild. Both reads give 18. The bytes on disk stayed the same. What changed was the number of independent file positions. That’s the kind of experiment I want from a systems book: change one call, predict the result, and find out which state belongs to your program and which belongs to Linux. dup(2) · read(2).

Why learn C when AI can write the whole program?

An agent can write a sophisticated program faster than I can read the code it produced. I get working software, but I can lose track of how it works. Does that matter? Sometimes I’m happy to plug something into the wall and get on with my day. If I were designing the substation that supplies the electricity, I’d want a different level of understanding. I think about software much the same way.

Embedded systems are why I wanted that depth. Some of my first glimpses of C came from Linux and the software that runs on routers. On a new board, one of the first things I want to do is read a peripheral register and see whether the chip behaves the way its documentation says it should. C is a common starting point for that kind of bring-up. I can ask an agent to write the test, look at the instructions the compiler produced, and compare the result on the board with what the hardware designer promised. If I’m testing how a processor handles an invalid access, I also need to know where C’s guarantees end. Dereferencing a null pointer is undefined in C. A chip-level fault test needs a documented access and an expected hardware response.

I picture C somewhere in the middle of a spectrum between physics and the applications we use. From a Python or JavaScript application, C can look like the bottom of the stack. From a chip designer’s desk, a C program is near the top. Take one expression, a[i] + b[i]. In the source I see two values and an addition. Below it I can ask which loads the compiler emitted, whether the data was already in L1 or had to come from L2, L3 or DRAM, and which registers feed the execution unit that does the add. I can inspect the assembly and measure cache misses if the answer matters. That ability to move between levels is what I value.

An application developer follows a library call down to C. A chip designer uses the same addition to check that the processor reads two inputs and stores the expected sum.
From the application side, I want to see how the sum is calculated. On the board, I already know the answer and want to see whether the hardware agrees. View full size.

It pays off even when I’m back working on a website. In my PHP article, the question was how a worker could still hold an address after the request that owned the memory had ended. In the nginx article, it was how a rewrite could produce more bytes than its destination had room for. Drawing the lifetime in one case and counting the bytes in the other made the security reports readable to me. It also gives me a concrete reason to consider Rust: when several parts of a program share data, I’d like the compiler to check who can still use it. Inside PHP’s 2026 Memory Bugs · Inside NGINX Rift.

These books helped me get started, and I’d still read them for that range. Reek taught me to draw the memory. The GCC book taught me how to see what my source became. Kerrisk helped me follow a C call into Linux. Today I can spar with an agent at each of those levels. If it tells me a change is faster, I can ask to see the generated instructions, then ask what happened on the actual processor. I get to decide how deep we go.

Would I write the next version in Rust?

For a board whose maintained driver, examples and debugger setup are all in C, I’d build the first working version in C. For a new component my team will maintain, especially one that passes buffers between tasks, I’d try Rust early. Can I flash and debug on our actual board? Does the peripheral driver exist? Can I express who owns the buffer and when another task may read it? Those answers matter more to me than picking one language for the whole product.

Here is the same exercise in safe Rust. The significant change is in the first line: &[i32] borrows a slice. Its length travels with it. The caller can lend the whole array or just the last two entries, and the function iterates over exactly that view. This example needs no heap allocation.

readings.rsrust
fn count_above(samples: &[i32], limit: i32) -> usize {
    samples.iter().copied().filter(|&value| value > limit).count()
}

fn main() {
    let samples = [18, 25, 31, 28];
    assert_eq!(count_above(&samples, 25), 2);
    assert_eq!(count_above(&samples[..2], 25), 0);
    assert_eq!(count_above(&samples[2..], 25), 2);
    assert_eq!(count_above(&[], 25), 0);
}

Save it as readings.rs and run rustc readings.rs -o test_rust && ./test_rust. The four assertions match the C exercise. Rust still accepts a mistaken >=, and a wrongly chosen slice can still describe the wrong sensor window. The language helps with memory access and borrowing; we still have to specify what the measurement means. Slices in The Rust Programming Language.

You can also keep an established C driver and write new processing code in Rust. At the boundary, someone must establish that the driver’s buffer is valid for the claimed length and stays valid for the whole borrow. On a microcontroller I’d also check support for the target and for running without the standard library. The Embedded Rust Book on no_std.

Two newer C books I’d add to the shelf

For a language update: Jens Gustedt’s Modern C, third edition, covers C23. I’d open it after K&R to answer a concrete question: if a library needs a buffer for rows × columns elements, how can it detect an overflow before allocating? Look up C23 checked integer arithmetic, then check whether the compiler and C library shipped with your target provide <stdckdint.h>. The earlier exercises deliberately use C17 so you can run them independently of that feature. Publisher’s edition details.

For reviewing real programs: Robert C. Seacord’s Effective C, second edition, also covers C23. Start with objects, functions and types. Bring a specific review question: if a function returns a pointer into a local array, when does that array’s lifetime end? That distinction between having an address and having a live object is worth learning in either language. Publisher’s page and sample chapter.

Where I’d start

If you have one evening, build the three files, deliberately leave out readings.o, and explain the error in your own words. If you can already do that, draw the pointer example from memory. Buy or borrow the book that answers the first question where you get stuck. That’s how these earned their place on my shelf.

Where I’d take this in part two: carry the same sensor buffer from C into Rust. Start with a borrowed slice on the desktop, then put the buffer behind a small C interface and ask who can safely keep it after a call returns. That gives us a reason to open the newer C books, a Rust ownership chapter and an embedded Rust reference at exactly the points where each earns its place.