Zum Inhalt springen
KodeTrail

Camp 1 · Schritt 3 von 12

How compilation works

Source to executable — the journey your C code takes, and the two moments errors can strike.

12 Min.+50 XPAuf Englisch angezeigt — Übersetzung ist unterwegs

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 it

On a real machine:

gcc hello.c -o hello      # compile into an executable named 'hello'
./hello                   # run it

gcc (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

CCloud-Run

%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:

  1. Delete a ;compile error. gcc refuses; no executable is produced.
  2. Change %d to %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.

Checkpoint

What does gcc hello.c -o hello produce?

Checkpoint

In printf("%d", count); what is %d?