7.1 — Two kinds of errors

📘 Chapter 7⏱ about 1 min read✍️ Beginner friendly
Read one box at a time. No rush.

Compile errors#

A compile error means the compiler can't understand your code. The program won't even be built.

C++ — wrong ✗
int x { 5 }std::cout << x;
Output
error: expected ',' or ';' before 'std'

These are the easy ones. The compiler tells you where to look.

Logic errors (bugs)#

A logic error means your code runs, but does the wrong thing. The compiler can't catch it, because the code is "correct C++" — it is just not what you meant.

C++
// meant to print the average of 4 and 5std::cout << 4 + 5 / 2;   // prints 6, not 4.5!
Bug

A mistake in a program that makes it act wrongly. Finding and fixing bugs is called debugging.

Key idea

Compile errors stop your program from building. Logic errors let it build, but it does the wrong thing. Both are totally normal.

Finished reading? Tick it off. Your progress is saved in this browser.

Tip: press ← / → to move between lessons, / to search.