---
title: "Types of errors and debugging"
subject: "Computer Programming"
chapter: 2
key: "semester_1/computer_programming:types-of-errors-debugging"
source: https://www.bctengineer.com/q/semester_1/computer_programming/types-of-errors-debugging
site: BCT Engineering
---

# Types of errors and debugging

Computer Programming · Chapter 2: Problem solving using Computer

- Asked in: 2073 Shrawan, 2+4 marks
- Video: [Programming Errors](https://www.youtube.com/watch?v=dPQaQWyqYoc) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/types-of-errors-debugging
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-2

## Question

Discuss the types of errors in programming. How do you debug a C-program?

## Short answer

Errors include syntax, logical, runtime, linker, and semantic types. Debug a C program by reading compiler messages, dry‑running, inserting printf statements, using a debugger with breakpoints, and testing with normal, boundary, and invalid data.

## Answer

#### Types of errors
1. **Syntax errors:** violation of the language rules, such as a missing `;` or misspelled keyword. Detected by the compiler; the program does not compile.
2. **Logical errors:** the program runs but gives wrong output because the logic is wrong, such as using `+` instead of `*`. No error message is shown.
3. **Runtime errors:** occur during execution, such as division by zero, invalid memory access or opening a missing file. The program stops abnormally.
4. **Linker errors:** a function used is not found when linking, such as a misspelled `prntf` giving "undefined reference".
5. **Semantic errors:** statements that follow the grammar but have no valid meaning, such as `a + b = c;` (a value cannot be assigned to an expression). The compiler reports them.

#### Debugging a C program
- Read the compiler's error and warning messages (compile with `gcc -Wall`) and fix the first error first, as one error can cause many.
- Trace the program by hand with sample data (dry run) and compare with the expected result.
- Insert `printf()` statements to display variable values at key points.
- Use a debugger (such as gdb or the IDE debugger) to set breakpoints, step through statements and watch variables.
- Divide the program into functions and test each separately.
- Test with normal, boundary and invalid data.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. A program that runs but gives wrong output because + was used instead of * has a
   A. logical error
   B. syntax error
   C. linker error
   D. runtime error
   Answer: A. No message is shown but output is wrong. (Key point: Logical error)

2. Division by zero during execution is a
   A. syntax error
   B. runtime error
   C. logical error
   D. linker error
   Answer: B. It occurs while running. (Key point: Runtime error)

3. 'undefined reference' from misspelled prntf is a
   A. syntax error
   B. runtime error
   C. linker error
   D. logical error
   Answer: C. The linker cannot find the function. (Key point: Linker error)

4. Which is a debugging technique?
   A. Delete the compiler warnings
   B. Run once with one input
   C. Ignore the first error
   D. Insert printf statements and use a debugger with breakpoints
   Answer: D. Printing values and debugger help locate errors. (Key point: Debugging technique)

## Related in Computer Programming

- [Computer program and programming](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adefine-program-programming) — Computer Programming, chapter 2
- [Debugging and testing](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Adebugging-testing) — Computer Programming, chapter 2
- [Correct program: case array and average](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Acorrect-program-case-array) — Computer Programming, chapter 3
- [Correct program: do-while and pow](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Acorrect-program-sum-root) — Computer Programming, chapter 3
- [Pattern: shrinking "Programming"](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apattern-programming-shrinking) — Computer Programming, chapter 4
- [Steps to develop a computer program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asteps-develop-program) — Computer Programming, chapter 2, asked 6×

## Related in other subjects

- [Why program inspections find errors](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Aprogram-inspection) — Software Engineering, chapter 7
- [Errors encountered during file operation](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afile-errors) — Object Oriented Programming, chapter 8
- [Faults, failures, errors; resilience](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Afaults-failures-resilience) — Distributed System, chapter 9
- [Mitigating DNL and harmonic distortion errors](https://www.bctengineer.com/question.md?key=semester_5%2Finstrumentation_ii%3Adnl-harmonic-distortion) — Instrumentation II, chapter 4
