Skip to content

Debugging: Reading Compiler Errors and Fixing Bugs

Programming C++ Difficulty 1/5

Beginning of the lesson

Debugging: Reading Compiler Errors and Fixing Bugs

Stay calm, read the message, and fix bugs one small step at a time

Big Idea: Every programmer writes bugs -- even the experts do, every single day. A bug is just a mistake in your code. The good news is that C++ usually tells you something is wrong. Learning to read those messages calmly, instead of panicking, is one of the most useful skills you can build.
By the end of this topic you will be able to:
  • tell apart compile-time errors, linker errors, and runtime bugs,
  • read a compiler message and find the file, line, and reason,
  • understand common messages like expected ';', undeclared identifier, and no matching function,
  • follow a calm, step-by-step routine to find and fix a bug.

1. From source code to a running program

Before we hunt bugs, let us see the journey your program takes. When you press "Run", the computer does three jobs in order:

  1. Compile -- the compiler reads your .cpp file and turns it into machine instructions. If your text breaks the rules of C++ (a missing semicolon, a misspelled name), it stops here with a compile-time error.
  2. Link -- the linker joins all the pieces together (your code plus the library code) into one runnable file. If a function was promised but never actually written, you get a linker error.
  3. Run -- the finished program actually executes. If it starts but does the wrong thing, or crashes halfway, that is a runtime bug.

Knowing which of these three stages failed already tells you a lot about where to look.

your file main.cpp COMPILE check the rules LINK join the pieces RUN program works compile-time errors here linker errors here runtime bugs here
Three stages: a problem shows up at the stage where a rule was broken.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers