0% found this document useful (0 votes)
23 views3 pages

Types of Errors

Types of errors occur in C program

Uploaded by

raviataitcse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Types of Errors

Types of errors occur in C program

Uploaded by

raviataitcse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Types of errors occur in C program

There are five different types of errors in C.

1. Syntax Error

2. Run Time Error

3. Logical Error

4. Semantic Error

5. Linker Error

Syntax Error

 Syntax errors occur when a programmer does not follow the set of rules
defined for the syntax of C language.
 Syntax errors are sometimes also called compilation errors because they
are always detected by the compiler.

The most commonly occurring syntax errors in C language are:

 Missing semi-colon (;)

 Missing parenthesis ({})

 Assigning value to a variable without declaring it.

Runtime Error

 Errors that occur during the execution (or running) of a program are
called RunTime Errors.
 These errors occur after the program has been compiled successfully.
When a program is running, and it is not able to perform any particular
operation, then error will be generated that is called a RunTime error.
 For example, while a certain program is running, if it encounters the
square root of -1 in the code, the program will not be able to generate an
output because calculating the square root of -1 is not possible. Hence,
the program will produce an error.
Runtime errors can occur because of various reasons. Some of the reasons
are:

1. Mistakes in the Code: Let us say during the execution of a while loop,
the programmer forgets to enter a break statement. This will lead the
program to run infinite times, hence resulting in a run time error.

2. Memory Leaks: If a programmer creates an array in the heap but forgets


to delete the array's data, the program might start leaking memory,
resulting in a run time error.

3. Mathematically Incorrect Operations: Dividing a number by zero, or


calculating the square root of -1 will also result in a run time error.

4. Undefined Variables: If a programmer forgets to define a variable in the


code, the program will generate a run time error.

Logical Error

 Sometimes, we do not get the output we expected after the compilation


and execution of a program. Even though the code seems error free, the
output generated is different from the expected one. These types of errors
are called Logical Errors.
 Logical errors are those errors in which we think that our code is correct,
the code compiles without any error and gives no error while it is
running, but the output we get is different from the output we expected.
 In 1999, NASA lost a spacecraft due to a logical error. This happened
because of some miscalculations between the English and the American
Units. The software was coded to work for one system but was used with
the other.

Semantic Error

 Errors that occur because the compiler is unable to understand the written
code are called Semantic Errors.
 A semantic error will be generated if the code makes no sense to the
compiler, even though it is syntactically correct. It is like using the wrong
word in the wrong place in the English language.
 For example, adding a string to an integer will generate a semantic error.
 Semantic errors are different from syntax errors, as syntax errors signify
that the structure of a program is incorrect without considering its
meaning. On the other hand, semantic errors signify the incorrect
implementation of a program by considering the meaning of the program.
 The most commonly occurring semantic errors are: use of un-initialized
variables, type compatibility, and array index out of bounds.

Linker Error

 Linker is a program that takes the object files generated by the compiler
and combines them into a single executable file.
 Linker errors are the errors encountered when the executable file of the
code cannot be generated even though the code gets compiled
successfully. This error is generated when a different object file is unable
to link with the main object file.
 We can run into a linked error if we have imported an incorrect header
file in the code, we have a wrong function declaration, etc.

You might also like