Preprocessor
A free lesson from Swipe Coding · C++, level 1 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
Before the actual compiler ever looks at your code, C++ runs it through a step called the "preprocessor". The preprocessor scans your source code for special instructions called "directives" — lines that start with a hash symbol "#" — and acts on them before real compilation begins.
The most common directive is "#include", which tells the preprocessor to copy the contents of another file directly into your source code. For example, "#include <iostream>" pulls in the declarations needed to print text to the screen.
#include <iostream>
int main() {
std::cout << "Hi!";
return 0;
}What does the preprocessor do with a line like "#include <iostream>"?
Another common directive is "#define", which can create simple text substitutions of its own, and "#ifdef" / "#endif", which can include or exclude sections of code entirely. All preprocessor directives are handled purely as text — the preprocessor doesn't understand C++ grammar, it just edits the text before the compiler sees it.
Preprocessor directives in C++ always begin with the character ____.
The preprocessor runs after the compiler has already translated the code into machine code.
Once the preprocessor has finished expanding directives like #include, the result is a single, expanded chunk of pure C++ source text — sometimes called a "translation unit" — which is finally ready to be handed to the compiler.
Keep your streak going in Swipe Coding
Swipe through every level of C++ on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →