Before the compiler runs, the preprocessor rewrites your text: directives starting with # never reach machine code.
1 A text pass first
Lines starting with # are handled before compilation — they edit the source text itself.
2 #include pastes
It literally copies the whole header file into your source at that line.
3 #define swaps
Every later use of the macro name is replaced by its body — no variables, no memory.
4 Macros can take arguments
#define DOUBLE(x) ((x) * 2) expands like a text template, wherever you call it.
The pass before the pass
A text pass first1Lines starting with # are handled before compilation — they edit the source text itself. #include pastes2It literally copies the whole header file into your source at that line. #define swaps3Every later use of the macro name is replaced by its body — no variables, no memory. Macros can take arguments4#define DOUBLE(x) ((x) * 2) expands like a text template, wherever you call it. 4 building blocks make up The pass before the pass
Press Run and watch where the # lines fit into the journey from source to binary.
A constant macro and a macro with an argument — see the swaps happen before the C code runs.
preprocessThe preprocessor pastes in stdio.h — printf comes from there.
Memory
no variables yet — press play
Console
output appears as the program runs…
Click a directive, then click what it does to lock the pair.
5 conceptsTap a card to expand ?#includedrops into place
?#define MAX 100drops into place
?#define SQ(x) ((x)*(x))drops into place
?#ifdef DEBUGdrops into place
?#endifdrops into place
The macro receives an expression — what does the swap produce?
Your predicted output — one line per console line
Hint: The macro expands textually: DOUBLE(a + 1) becomes ((a + 1) * 2) — the parentheses keep it safe.
01Everything starting with # is handled before compilation — it is text processing.
02#include pastes a file; #define swaps names for text.
03Macro parameters have no type checking — wrap them in parentheses.
04Uppercase names like MAX tell readers "this came from the preprocessor".
05Header guards (#ifndef / #define / #endif) prevent double-pasting.