- 2073 Shrawan · 2+4 marks
Types of errors and debugging
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.
Discuss the types of errors in programming. How do you debug a C-program?
Types of errors
- Syntax errors: violation of the language rules, such as a missing
;or misspelled keyword. Detected by the compiler; the program does not compile. - Logical errors: the program runs but gives wrong output because the logic is wrong, such as using
+instead of*. No error message is shown. - Runtime errors: occur during execution, such as division by zero, invalid memory access or opening a missing file. The program stops abnormally.
- Linker errors: a function used is not found when linking, such as a misspelled
prntfgiving "undefined reference". - 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.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Computer program and programming · Computer Programming, chapter 2
- Debugging and testing · Computer Programming, chapter 2
- Correct program: case array and average · Computer Programming, chapter 3
- Correct program: do-while and pow · Computer Programming, chapter 3
- Pattern: shrinking "Programming" · Computer Programming, chapter 4
- Steps to develop a computer program · Computer Programming, chapter 2 · asked 6×
- Why program inspections find errors · Software Engineering, chapter 7
- Errors encountered during file operation · Object Oriented Programming, chapter 8
- Faults, failures, errors; resilience · Distributed System, chapter 9
- Mitigating DNL and harmonic distortion errors · Instrumentation II, chapter 4