Custom Search

Monday, 9 January 2012

Types of Errors in C or C++, Runtime Error, Logical Error, Syntax Error, Explain type of Errors in C or C++ with Example

Types of Errors in C or C++, Runtime Error, Logical Error, Syntax Error, Explain type of Errors in C or C++ with Example


Errors in C are catagorised in 3 Parts i.e Syntax error, Logical Error & Runtime Error. I willl explain you all of these in detail

1.Syntax Error
This type of error occurs basically due to incorrect statement formation, which are not according to the format or rules of the c programming language.

For eq.

Incorrect
#include<iostream.h>
#include<conio.h>
void main()
(
int number,
char name,
getch();
)

Correct
#include<iostream.h>
#include<conio.h>
void main()
{
int number;
char name;
getch();
}

2.Logical Errors:-
This type of error occurs basically when there is error in the concept or logic of the program written.
For eg if i am making a c program to form of calculator and in the place of adding number i have use "+" instead of "-".
i such a error occurs than the whole program produces wrong result.

3.Runtime error:-
Runtime error occurs basically during the runtime in this case case our program is compiled with no errors but when start executing it it shows errors.
For eg.
#include<iostream.h>
#include<conio.h>
void main()
{
int n,m,d;
printf("Enter the value of m & n", &m &n);
d=m/n
printf("answer is", d)
getch();
}

in the above program if i enter the value of n as 0 than the output produced will be wrong.

Runtime error may also occur due to logarithm of a negative number or find the square root of a negative integer.

No comments:

Post a Comment

Laptops