Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction to C++  ›  Lesson

What Is C++?

What is C++? 12 minC++ is a compiled, statically typed, general-purpose language that turns source code into machine code before the program runs.

What Is C++?

Imagine you are building Rocket Run, a small arcade game: a rocket dodges asteroids, collects coins and tries to beat a high score. It must redraw the screen dozens of times a second on anything from a gaming PC to a cheap laptop. That kind of job is exactly what C++ was designed for, and Rocket Run will be our example for the whole course.

The rule

C++ is translated to machine code before it runs, and checked on the way.

Three ideas are packed into that line.

  • Compiled. A program called a compiler reads your source file and translates it into machine code, the instructions your processor executes directly. The finished program runs without the compiler.
  • Checked. Every variable has a type fixed in the source, such as int for whole numbers. The compiler checks all of them before producing anything. This is called static typing.
  • General purpose, many styles. You can write plain step-by-step functions, group data and behaviour into classes, or write generic code with templates. C++ lets you mix all three.

Here is the smallest piece of Rocket Run:

#include <iostream>

int main() {
    int lives = 3;
    std::cout << "Lives: " << lives << '\n';
}

A little history helps the names make sense. Bjarne Stroustrup started the language at Bell Labs in 1979 as "C with Classes", and it was renamed C++ in 1983 (++ means "add one" in C). Today an ISO committee publishes a new standard every three years: C++11, 14, 17, 20 and 23. This course uses C++17 and C++20.

The shortcut

When someone asks "what happens to my C++ code?", picture a factory line: source → compiler → executable → run. Anything wrong with types is caught at the compiler stage, long before the run stage.

From rocket.cpp to a running gameStep 1 of 4
  1. Write the source

    You type the code above into a text file called rocket.cpp. It is only text; nothing can run it yet.

A common mistake is to think C++ reads your file line by line as it runs, the way a Python interpreter does. It does not: by the time anything runs, the whole file has already been translated.

Drills

Answer fast — trust the rule.

quick drill

What does the compiler produce from rocket.cpp?

quick drill

When is the mistake in int lives = "three"; reported?

quick drill

Which programming styles does C++ support?

quick drill

Who decides what counts as correct C++?

Remember

  • C++ is translated to machine code before it runs, and checked on the way.
  • Picture the line: source → compiler → executable → run.
  • Trap: C++ is not interpreted line by line; type errors stop the build, not the game.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhy the mistake never ran

A friend writes int lives = "three"; in Rocket Run and is surprised that the program will not even start. Explain what happened, using the words compiler, machine code and type.