Hello, C!
C built the modern computing world. Operating systems, databases, embedded firmware, compilers. Most of the plumbing you rely on every day was either written in C or shaped by it.
This track teaches C from the ground up, with one obsession: direct control over memory.
Your First C Program
Every C program starts with a main function. The simplest program looks like this:
#include <stdio.h>
int main() { printf("Hello, world!\n"); return 0;}Four lines, four ideas:
#include <stdio.h>tells the preprocessor to pull in the standard I/O library. Drop it andprintfvanishes.int main()is the entry point. When the OS launches your program, this is the function it jumps to.printf("Hello, world!\n")writes text to the terminal. That\nis a newline.return 0;tells the OS the program finished cleanly. Anything nonzero usually means something went wrong.
C is a compiled language. You write source in .c files, a compiler (GCC, Clang) chews it into machine code, and your CPU runs that code directly. Nothing sits between you and the hardware. No interpreter, no VM, no JIT.
Compilation
To compile and run a C program on the command line:
gcc hello.c -o hello./helloThe compiler reads hello.c, spits out machine code, and stuffs it into an executable called hello. Run ./hello and the OS maps that file into memory, then jumps to main.
That one gcc command hides four separate programs run back to back. You don't need the details yet, but it helps to know the stages exist, because error messages tell you which one complained:
The misspelled-printf error in the runner below comes from that last step, the linker. From Source to Binary takes each stage apart later in the track.
The runner below does both steps for you on a Linux box. Run it once as it stands, then change return 0; to return 3;: the status line stops saying Accepted and reports a non-zero exit code, which is exactly what a shell script checking $? would see.
One Run, Step by Step
Here's what happens to that program from the moment you type ./hello, with the real values at each step:
- The shell asks the kernel to start
hello. The kernel loads the file, gives the process a fresh stack, and runs a little start-up code from the C library, which then callsmain. printfgets a string of 14 characters: the 13 inHello, world!plus the newline. There are no%codes to fill in, so it copies those 14 bytes into a buffer the C library keeps forstdout.- Because
stdoutis a terminal and a newline just arrived, the library passes all 14 bytes to the kernel in a singlewritesystem call aimed at file descriptor 1, standard output. The kernel draws them in your terminal. return 0;leavesmain. The C standard says returning frommaindoes the same as callingexitwith that value, so the library flushes anything still buffered, closes its streams and hands 0 to the kernel.- The kernel passes that status to the parent process, your shell, which stores it in
$?.
On Linux, strace ./hello lets you watch step 3. Near the end you'll find write(1, "Hello, world!\n", 14) = 14, where the last 14 is how many bytes the kernel accepted. In the runner, stdout is a pipe rather than a terminal, so the bytes wait in the buffer until step 4 flushes them: same bytes, slightly later. Standard I/O Streams covers buffering properly.
Predict: change the last line to return 300; and run it. What exit code comes back?
- The parent only receives the lowest 8 bits of the status (
status & 0xFF), so exit codes wrap at 256, and 300 − 256 = 44. That's why programs stick to 0 for success and small numbers like 1 or 2 for failure. Try it in the runner to check.
main() or main(void)?
You'll see both spellings. Before C23, empty parentheses in a function definition meant "no parameters" but didn't give the function a prototype, so the compiler wouldn't complain if something called it with arguments. int main(void) says outright that there are none, and it's the form the rest of this track uses. C23 made the two mean the same thing.
When a program wants its command-line arguments, main takes two parameters instead: int main(int argc, char *argv[]). argc counts the arguments and argv is an array of strings, with argv[0] normally holding the name the program was run as. Run ./hello one two and argc is 3.
Why C for Low-Level Learning?
C hands you a loaded gun and walks away. No garbage collector, no array bounds checks, no runtime to catch the mistakes you make at 2am. That sounds like a flaw, and for production code it often is. For learning, it's the whole point.
- You see how memory works because you're the one moving it around.
- You get pointers because you can't write five lines of C without them.
- You appreciate what Python and friends quietly handle because, here, nobody's handling it.
Stack frames, heap allocation, pointers, memory layout — every concept from the fundamentals track stops being abstract the moment you write C.
What We Will Build
By the end of this track, you'll have built a working key-value store in C. It stores, retrieves, and persists data through a hash table, file I/O, and a small command-line interface. Each module bolts on another piece.