Camp 1 · Step 3 of 12
How compilation works
Source to executable — the journey your C code takes, and the two moments errors can strike.
C is a compiled language: your human-readable code is translated, once, into machine code the CPU runs directly. Understanding the steps explains every error you'll meet.
From .c to running program
hello.c ──(compiler)──▶ hello (executable) ──▶ output
source gcc machine code the CPU runs itOn a real machine:
gcc hello.c -o hello # compile into an executable named 'hello'
./hello # run itgcc (the GNU C Compiler) reads your source, checks it, and — only if
it's valid — produces a standalone executable of raw machine code. That
file needs no interpreter; the CPU speaks it natively. This is why C is
fast, and why you compile before running.
Two moments, two kinds of error
%d is a placeholder — printf substitutes the integer lessons for
it. (%d for ints, %f for floats, %s for strings.) Now break it two
ways:
- Delete a
;→ compile error.gccrefuses; no executable is produced. - Change
%dto%s(wrong type) → it may compile but misbehave at runtime — undefined behavior, C's famous sharp edge.
Compile errors are caught before your program exists. Runtime errors hide until execution. C, being close to the metal, trusts you more — and punishes mistakes harder — than Python would.
What does gcc hello.c -o hello produce?
In printf("%d", count); what is %d?