Skip to content

Compiler

In one line

A compiler is a program that translates source code into machine code all at once, before the program runs.

In simple words

A compiler is a special program that takes your source code (written in a language like C, C++, or Java) and translates it entirely into machine code — the binary instructions the CPU can execute directly. This translation happens before the program runs.

The advantage of compilation is speed: since the code is pre-translated, the program starts and runs fast. The disadvantage is that you must recompile every time you change the code, which slows down development.

Compiled languages include C, C++, Rust, Go, and Java (compiled to bytecode). Each has its own compiler: gcc for C, javac for Java, rustc for Rust. The compiler also catches syntax errors before you run the program, giving you a chance to fix them.

Example

bash
# Compile a C program
$ gcc program.c -o program

# Run the compiled program
$ ./program
Hello, World!

gcc compiles program.c into an executable called 'program'. You then run the executable directly.

Common confusions

  • Confused with: interpreter

    The difference: A compiler translates all code before running (faster execution, slower development); an interpreter translates line-by-line at runtime (slower execution, faster development).

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary