# Debugging a program — C++

Source: https://www.geekswithgeeks.com/en/cpp/cpp-debugging

> Use Debugging a program confidently by explaining its purpose, trying a small program, and checking the result.

## The essential idea

**Debugging a program** is easier when you first name its job: it helps a program store information, make a decision, or perform a repeatable action. Do not rush to syntax. Ask what value changes, who owns it, and what result you expect.

## Run a tiny experiment

Read the code from top to bottom, then run it. The output is evidence, not something to guess.

```cpp
// Practise one debugging idea at a time.
int value = 0;
std::cout << value << "\n";
```

Output:

```
0
```

## A common mistake

Students often treat **Debugging a program** as a rule to memorize. Instead, compile a four-line example, predict its output, and let the compiler correct your mental model. Compiler errors are precise clues, not a verdict on you.

Check your learning habit.

**Quiz:** Which is the best way to learn Debugging a program?

- [x] Build and test one small example.
- [ ] Memorize code without running it.
- [ ] Ignore compiler messages.

*Answer:* Build and test one small example.. A small program makes cause and effect visible; then you can change one thing and observe it.
