Debugging:
Bug is anything wrong in the program that may lead to malfunction of the program, giving us unexpected results.Debugging is a process of removing or rectifying these bugs. So learning to debug a program is an important aspect for any programmer. In fact there are career opportunities that are completely dedicated towards debugging.
Now we learn about the types of errors we encounter when we write a program. Errors can be of three types:
1.Run time errors:
Some programs may be correct in syntax but produce errors during execution. These are generally due to illegal operations (sometimes due to negligence of the programmer) or system malfunctions. Some of the examples for such type of errors are:
a. Dividing a number by zero
b. No memory available
c. Accessing a file that is not created.
d.Accessing arrays out of bounds
e. Dangling pointer issues.
These errors can be averted by being careful while writing a program and making sure everything is fine with the system before execution (like enough memory space, enough rights to execute the program etc).
2.Compiler errors:
When we don't follow the formal rules of a programming language, then the compiler couldn't understand the instruction, and it raises errors. The compiler can still detect the type of error we committed. These errors can be of two types:
Syntactical errors:
These error are raised by the compiler when we don't follow the correct structure of writing an instruction. For example, writing a wrongly spelled keyword.
Eg: vooid main()------> error as 'void' is spelled wrong.
Semantic Errors:
These type of errors are raised by the compiler when the compiler cannot understand the statement written by us,
Eg: a*b=c;----> this is wrong , as c can't be assigned to a*b;
further c=a*b; is correct.(c is assigned with a*b)
These type of errors can be avoided by following the correct syntax and rules of the programming language used.
3.Logical Errors:
These errors are harder to be rectified. Compilers doesn't rise an error but we may get unexpected results. For example, in a program to if we try to print a floating point value using %d as format specifier, then the decimal part will be truncated. Also if precedence and associativity is wrongly handled.
It is harder to catch these errors, we some times need to check line by line to find out the error. Finding these errors would become more faster with practice.
Sign up here with your email
ConversionConversion EmoticonEmoticon