Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

How C++ Works · Lesson 6 of 25

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 your code is even compiled, a first pass edits the text itself. ✂️

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;
}
Before compiling, the preprocessor replaces "#include <iostream>" with the entire contents of that header file.
Quick check

What does the preprocessor do with a line like "#include <iostream>"?

🤖
Directives are easy to spot — just look for the # at the start of the line. 🔎

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.

Fill in the blank

Preprocessor directives in C++ always begin with the character ____.

True or false

The preprocessor runs after the compiler has already translated the code into machine code.

🤖
Text edited, ready to compile — that's next. ➡️

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 →