Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

How C++ Works · Lesson 7 of 25

Compiler

A free lesson from Swipe Coding · C++, level 1 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Your expanded source text still needs a translator into real machine instructions. 🔧

Once the preprocessor has finished, the "compiler" takes over. The compiler reads your (now expanded) C++ code and translates it into "object code" — machine instructions specific to your computer's processor. Common C++ compilers include g++ (GCC), clang++, and Microsoft's MSVC.

Unlike some other languages, the C++ compiler translates your code straight toward native machine instructions for your specific processor and operating system — not into some universal, platform-independent middle format. This is one reason C++ programs can run so fast: there is no extra translation step left to do once compiling is done.

g++ -c main.cpp -o main.o
This command tells the g++ compiler to translate main.cpp into an object file called main.o (the "-c" means "compile only, don't link yet").
Fill in the blank

The C++ compiler translates source code into ____ code, made up of native machine instructions.

🤖
Not quite a finished program yet — there is one more piece missing. 🧩

The output of the compiler is stored in an "object file" (extension ".o" on Linux/macOS, ".obj" on Windows). Importantly, an object file on its own usually is not yet a runnable program — especially if your code calls functions defined elsewhere, like printing text to the screen, which live in the standard library.

The compiler also checks your code for errors along the way. If you misspell a keyword, forget a semicolon, or use a variable incorrectly, the compiler stops and reports a "compile error" — no object file is produced until the mistake is fixed.

Quick check

What happens if your C++ source code contains a mistake, like a missing semicolon?

True or false

An object file produced by the compiler is always immediately runnable on its own.

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 →