An illuminated 'hello' sign on a wall. Photo · atelierbyvineeth / Unsplash
The first program every C programmer writes. Five lines. Every word matters.

It is 1978. Brian Kernighan and Dennis Ritchie are sitting in a Bell Labs office, finishing the manuscript of The C Programming Language. They need an example. Something tiny, that prints something to the screen, that introduces the rituals you'll perform in every C program you ever write.

They write five lines. The program prints the words "hello, world". Forty-seven years later it is, very probably, the most-written, most-translated, most-imitated program ever produced. It is the universal "I have a working compiler" handshake. It is the first thing a programming language teaches.

And it is a perfect dissection target — because every word in it leads somewhere. Today we read it slowly and look at every line.

The whole program

#include <stdio.h>

int main(void) {
    printf("hello, world\n");
    return 0;
}

Five lines. Save this as hello.c, run cc hello.c -o hello && ./hello, and you'll see:

$ ./hello hello, world

Now we go through it phrase by phrase.

Line by line

A fountain pen lying on a sheet of black lined paper. Photo · Aaron Burden / Unsplash

Every word counts. Five lines, one program, half a dozen ideas hiding in plain sight.

What actually happens when you run it

You typed ./hello. Here's the sequence, end to end, in less than a millisecond:

  1. The shell asks the kernel to run the file ./hello. The kernel checks it's an executable, reads the first few bytes (the "magic number") to confirm, and prepares a fresh process.
  2. The kernel maps the executable into memory — code section, data section, stack, heap. It sets up the program counter to point at a tiny bit of startup code that the C runtime injected, called _start.
  3. _start sets a few things up (initialises globals, finds the command-line arguments) and then calls main.
  4. main calls printf. printf looks at its argument, identifies that no special % placeholders need substituting, and asks the kernel — via the write syscall — to write 13 bytes to file descriptor 1 (standard output).
  5. The kernel writes those bytes. Your terminal program, watching that file descriptor, paints them on the screen.
  6. printf returns. main hits return 0. _start takes that return value and calls the exit syscall with it. The kernel cleans up the process. The shell prints a fresh prompt.

Six steps. Hundreds of thousands of CPU cycles. A trip from your shell to the kernel, into a C runtime, through your code, back through the runtime, back to the kernel, back to the shell. All of that, every time. And you don't see any of it — you just see hello, world.

Why this program is the universal first program

Because it touches every part of the machinery you'll ever need:

Six fundamental concepts in five lines, none of them strictly necessary for printing "hello, world" — you could imagine a language where print "hello" was the entire program. C made the deliberate decision to expose the scaffolding from day one. You learn the rituals before you do anything interesting, and that pays off the rest of your career.

Some variations to try

Once you have the program working, deliberately break it. There is no faster way to learn what each piece is doing than to remove it and see what the compiler shouts.

Why this matters for AI

Every CUDA file you ever read starts with #include <cuda_runtime.h>. Every PyTorch C++ extension starts with #include <torch/extension.h>. Every llama.cpp source file you'll ever browse begins with this same ritual. main, headers, return codes — these aren't C trivia. They are the entry point of every native program in the AI stack.

Writing your own hello.c matters because, surprisingly often, when something goes wrong in a deep AI install, you'll find yourself fixing a 30-year-old C build error two libraries down. Knowing what #include means, knowing what main is, knowing what a "return value of 1" really represents — that is suddenly your problem. And then it stops being mysterious.

Every C program ever written has the same skeleton. Once you can see it, you can see it everywhere.

Try it yourself

If you set up a compiler last week, this is your moment. If not, see Week 9's "try it yourself" first.

Welcome. You have officially run a C program.

What's next

Now we make the program actually do something. Hello world has no inputs, no logic, no state. From next week we start working with values — and to do that, we need somewhere to put them.

Week 12 is Variables & Memory — telling the RAM how much space you need, why int and char aren't the same number of bytes, and what your computer is doing under the hood when you say int x = 5;.

Photo credits

All photos are free under the Unsplash license. Hello sign · atelierbyvineeth · Pen · Aaron Burden.