In: Computer Science
How many types of errors can occur during the execution of a program? Discuss the circumstance when these types of errors can occur. Support your argument with examples.
Types of Errors
Errors are a type of mistake in a program that is, errors are found by the compiler when there is something went wrong or the program shows something unexpectedly. Errors(bugs) are of mainly 3 types.
They are,
1. Syntax error
2. Logical error
3. Runtime error
1)Syntax error
Based on C programming, the compiler will found this type of errors only when the compiler try to compile the program. Mainly this is occur due to the violation of spelling or grammer followed by the language. That is the statement,
printf("Welcome to programming")
Actually the above statement must end with a semicolon. That is one of the rule followed by C language.
But here, the semicolon is missed, so there will occur an error while compiling the program.
As the same, when some times we forget to declare a variable that is used in in the program, and also missing some punctuations followed by the language there should have occur syntax error.
Example
2)Logical error
The main problem of this error is that, sometimes we cannot find this types of Errors easily. Because this is occurs due to the logical mistake applied by the programmer. To fix this error we should have to cross check our program. It doesn't shows any error messages like syntax error. If occuring something like that, we have to find the mistake and correct it quickly. But in this case it is not possible to find the error in this way. As a result of this error, we will get incorrect output. For an example, we are declaring three varibles a,b and c in our program, and calculating b=a+b; instead of c= a+b;
If we try to print the result in c variable, we will never get the correct answer. So logical error is occurs due to the carelessness logic applied by the programmer.
3) Runtime Error
If the program is free from syntax error, then it will compiled successfully by the compiler. After that it will end and exit from the output solution unexpectedly. So we have to check or think about the chance of Errors that will occur at runtime. Such type of error leads the process termination.
For example, if we are performing a division operation, and it compiled successfully, then enter the first number as 10 and sencond or the divisor is 0, then it should perform a division by zero operation, so it will leads to an unexpected termination of the program.
Like that, if an array size is declared as 5, and we are try to insert 6 elements into it , there will also a quick termination. It is also says that crashing of a program.
This is a clear explanation of errors in a programming language. If you can't understand or still have any doubt don't feel bad to comment it. Otherwise don't forget to upvote.