Skip to content
FollowtheDamnCode

Your First C Program

main(), printf, and running real code.

4 minute read

Big idea

Every C program starts running in the same place: main.

The idea

Here is a complete C program. It prints one line:

Try it — edit it and run it again
#include <stdio.h>

int main(void) {
    printf("Hello, World!\n");
    return 0;
}
output
Hello, World!

Run and edit it in the app.

Line by line:

  • #include <stdio.h> — brings in the toolbox that has printf.
  • int main(void) { — the program starts here.
  • printf("..."); — prints the text in quotes. \n means new line.
  • return 0; — "finished, all good".
  • } — end of main.

Watch it

Think of it like

A recipe card. #include is "tools you'll need". main is step 1 — the cook always starts there. Each printf is one step.

🕷️ Spidey-sense: Every hero has an origin story — main is your program's. The computer always starts there. And that ; at the end of a line? It's the knot on my web-line: forget it and everything falls apart.

Pressing Run for the first time is your leap of faith, Miles-style. It might not work first try. That's fine — nobody's first swing was a clean one.

Common mistake

Forgetting the semicolon ; at the end of a line. Every instruction in C ends with one.

printf("Hi\n")    // ✗ error: expected ';'
printf("Hi\n");   // ✓

Key terms

  • main — Where every C program starts running.
  • printf — Prints text to the screen.
  • \n — Moves to a new line.

Check yourself

Where does every C program start running?

What does #include <stdio.h> give your program?

What does \n do inside printf("Hi\n")?