0% found this document useful (0 votes)
99 views9 pages

Errors in C

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

Errors in C

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

Types of error

There are five types of error in C

1.Syntax error

2.Run Time error

3.Linker error

4.Logical error

5.Semantic error

* 1
ERRORS CONTINUE..

Syntax error:
• The errors which arises due to violation of any rule or regulation of C language during
the development of program those errors are known as Syntax error.
•Syntax errors are also known as the compilation errors as they occurred at the
compilation time, or we can say that the syntax errors are thrown by the compilers. These
errors are mainly occurred due to the mistakes while typing or do not follow the syntax of
the specified programming language.
Examples:-
1.Missing of semicolon.
2.If we miss the parenthesis (}) while writing the code.
3.Displaying the value of a variable without its declaration.

* 2
ERRORS CONTINUE..
Examples with code
1.If we want to declare the variable of type integer,
int a; // this is the correct form
Int a; // this is an incorrect form. .
2. #include <stdio.h>
int main()
{
a = 10; // a is not declared
printf("The value of a is : %d", a);
return 0;
}
3. #include <stdio.h>
int main()
{
int a=2;
if(.) // syntax error we put the (.) instead of condition in 'if', so this generates the syntax error
printf("a is greater than 1");
return 0;
}

* 3
ERRORS CONTINUE..

• Runtime error: The error which occurs during the execution of program those errors
are turn termed as runtime error.
Sometimes the errors exist during the execution-time even after the successful
compilation known as run-time errors. When the program is running, and it is not able
to perform the operation is the main cause of the run-time error. The division by zero
is the common example of the run-time error. These errors are very difficult to find, as
the compiler does not point to these errors.
Example
1.Devision by zero.

* 4
ERRORS CONTINUE..
Linker error
•Linker errors are mainly generated when the executable file of the program is
not created.
•This can be happened either due to the wrong function prototyping or usage of
the wrong header file.

* 5
ERRORS CONTINUE..
Linker error
•Linker errors are mainly generated when the executable file of the program is
not created.
•This can be happened either due to the wrong function prototyping or usage of
the wrong header file.
•The most common linker error that occurs is that we use Main() instead of
main().
• Example using print() instead of printf().
•. These error are identified during linking object code with system library.
#include <stdio.h>
int Main() // Linker error
{ int a=78;
printf("The value of a is : %d", a);
return 0;
}* 6
ERRORS CONTINUE..
Logical error
• The errors which are introduced due to usage of wrong expression formula
for logic in program these errors are called as logical error for example using 2
* 3.14 as area of circle.
•The logical error is an error that leads to an undesired output.

•These errors produce the incorrect output, but they are error-free, known as
logical errors.
•These types of mistakes are mainly done by beginners. The occurrence of
these errors mainly depends upon the logical thinking of the developer.
• If the programmers sound logically good, then there will be fewer chances of
these errors.

* 7
ERRORS CONTINUE..
#include <stdio.h>
int main()
{
int sum=0; // variable initialization
int k=1;
for(int i=1;i<=10;i++); // logical error, as we put the semicolon after loop
{
sum=sum+k;
k++;
}
printf("The value of sum is %d", sum);
return 0;
}

* 8
ERRORS CONTINUE..
Semantic error :
These are valid code the compiler understands, but they do not what you, the
programmer, intended.The following can be the cases for the semantic error:

1.Use of a un-initialized variable.

int i;

i=i+2;

2.Type compatibility

int b = "MIET";

3.Errors in expressions

int a, b;
b = a+”hi” ; 4.Array index out of bound

int a[10];
a[10] = 34;
* 9

You might also like