14. Debugging.
md 2026-06-24
Chapter 16 : Debugging
16.1 Introduction
While developing a program, errors may occur that prevent it from working correctly. The process of finding
and correcting these errors is called Debugging.
Debugging is an important part of software development because it helps improve the accuracy and reliability
of programs.
16.2 What is Debugging?
Debugging is the process of identifying, analyzing, and removing errors (bugs) from a program.
A bug is any error or defect that causes a program to produce incorrect results or behave unexpectedly.
Definition: Debugging is the process of detecting and correcting errors in a program.
16.3 Debugging Process
The debugging process generally involves the following steps:
1. Identify the Error
Detect that an error exists in the program.
2. Locate the Error
Find the exact part of the code causing the problem.
3. Analyze the Cause
Understand why the error occurred.
4. Correct the Error
Modify the code to remove the error.
5. Retest the Program
Run the program again to ensure the issue has been fixed.
16.4 Syntax Errors
Syntax errors occur when programming language rules are violated.
These errors are detected by the compiler or interpreter before program execution.
Causes
Missing semicolon
1/4
14. [Link] 2026-06-24
Missing brackets
Incorrect keywords
Misspelled commands
Characteristics
Prevent program execution.
Easy to detect and fix.
Reported by compiler/interpreter.
Example
[Link]("Hello"
Missing closing parenthesis causes a syntax error.
16.5 Runtime Errors
Runtime errors occur while the program is executing.
The program starts successfully but stops when an invalid operation occurs.
Causes
Division by zero
Invalid file access
Memory overflow
Invalid user input
Characteristics
Occur during execution.
Cause program interruption.
Difficult to predict sometimes.
Example
let x = 10 / 0;
May produce unexpected results during execution.
16.6 Logical Errors
Logical errors occur when the program runs successfully but produces incorrect output.
These errors are caused by mistakes in the program logic.
2/4
14. [Link] 2026-06-24
Causes
Incorrect formula
Wrong condition
Incorrect algorithm
Faulty calculations
Characteristics
No error message generated.
Program executes normally.
Output is incorrect.
Example
Area = Length + Breadth
Correct formula should be:
Area = Length * Breadth
Difference Between Errors
Syntax Error Runtime Error Logical Error
Violates language rules Occurs during execution Produces wrong output
Detected before execution Detected while running Difficult to detect
Program does not start Program crashes/stops Program runs normally
Easy to fix Moderate difficulty Most difficult to find
16.7 Debugging Techniques
Several techniques are used to locate and fix errors.
1. Dry Run
Manually execute the program step by step.
2. Trace Table
Track variable values during execution.
3. Print Statements
Display intermediate values to locate errors.
3/4
14. [Link] 2026-06-24
4. Breakpoints
Pause execution at specific points and inspect variables.
5. Code Review
Examine the code carefully to identify mistakes.
6. Testing
Use different test cases to detect errors.
Benefits of Debugging
Improves software quality.
Increases reliability.
Helps identify hidden defects.
Produces accurate results.
Reduces future maintenance efforts.
Key Definitions
Bug: An error or defect in a program.
Debugging: The process of finding and correcting bugs.
Syntax Error: Error caused by violation of programming language rules.
Runtime Error: Error occurring during program execution.
Logical Error: Error that produces incorrect results without stopping execution.
4/4