Debugging in C – Notes
1. Debugging: Identify and Fix Errors
What is Debugging?
Debugging is the process of identifying, locating, analyzing, and fixing errors (bugs) in a program so
that it executes correctly and produces the expected output.
In C programming, errors can occur at different stages such as writing, compiling, or executing the
program. Debugging helps programmers understand why a program is not working as intended and how
to correct it.
Why Debugging is Important
• Programs may not compile due to mistakes
• Programs may run but give wrong output
• Programs may crash during execution
• Debugging improves program correctness and reliability
Steps to Identify and Fix Errors
1. Identify the Error
2. Observe compiler error messages
3. Check incorrect or unexpected output
4. Analyze the Error
5. Find the line where the error occurs
6. Check syntax rules, logic, and variable usage
7. Fix the Error
8. Correct syntax mistakes
9. Modify logic or conditions
10. Add proper checks
11. Test the Program Again
12. Recompile and run the program
1
13. Verify correct output
Common Errors in C Programs
• Missing semicolon ;
• Wrong format specifier in printf() or scanf()
• Incorrect loop conditions
• Array index out of range
• Division by zero
2. Different Types of Debugging Techniques
1. Manual Debugging (Dry Run Method)
• Program is executed step by step on paper
• Variable values are traced manually
• Very useful for beginners
2. Printf Debugging
• Uses printf() statements to display variable values
• Helps track program execution and logic
Example:
printf("Value of i = %d", i);
3. Compiler-Assisted Debugging
• Compiler detects syntax errors
• Error messages indicate line number and type of error
Examples: - Missing semicolon - Undeclared variable
4. Debugging Using Debugger Tools
• Uses built-in debugging tools in IDEs
• Allows setting breakpoints
• Executes program line by line
• Displays real-time variable values
2
Examples of IDEs: - Code::Blocks - Dev-C++ - Visual Studio Code
5. Logical Debugging
• Used to detect logical errors
• Program runs but output is incorrect
• Requires checking conditions and algorithm
6. Boundary Value Debugging
• Checks array limits and loop boundaries
• Prevents accessing invalid memory locations
7. Divide and Conquer Debugging
• Breaks program into smaller parts
• Each part is tested separately
• Helps locate errors faster in large programs
Short Exam Notes
• Debugging is the process of finding and fixing errors in a program.
• Syntax errors are detected at compile time.
• Runtime errors occur during program execution.
• Logical errors produce incorrect output.
• printf() is commonly used for debugging in C.
Conclusion
Debugging is an essential part of C programming. By using proper debugging techniques, programmers
can efficiently identify errors, fix them, and improve the quality and correctness of their programs.