Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Programming Errors in C

Uploaded by

Chetan Cherry
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Programming Errors in C

Uploaded by

Chetan Cherry
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Programming Errors in C

Errors are the problems or faults that occur in the program, which make
the program's behavior abnormal. Programming errors are also known
as bugs or defects, and the process of removing these bugs is known as
debugging.
These errors are detected either during the �me of compila�on or
execu�on.

There are five types of errors exist in C programming:


• Syntax error
• Run-�me error
• Linker error
• Logical error
• Seman�c error
Syntax error

These errors mainly occur due to mistakes while typing or do not follow
the syntax of the specified programming language. These errors can be
easily debugged.

For example:

If we want to declare the variable of type integer,

int a; // this is the correct form.

Int a; // this is an incorrect form.

Commonly occurred syntax errors are:

• If we miss the parenthesis (}) while wri�ng the code.


• Displaying the value of a variable without its declara�on.
• If we miss the semicolon (;) at the end of the statement.

Let's understand through an example.

Output

In the above output, we observe that the code throws the error that 'a' is undeclared. This
error is nothing but the syntax error only.
Run-time error

Some�mes the errors exist during the execu�on �me even a�er the
successful compila�on known as run-�me errors. When the program is
running, and it is not able to perform the opera�on is the main cause of
the run-�me error. The division by zero is a common example of the run-
�me error. These errors are very difficult to find, as the compiler does not
point to these errors.

Let's understand through an example.

Output
Linker error

This can happen either due to the wrong func�on prototyping or the
usage of the wrong header file. For example, the main.c file contains
the sub() func�on whose declara�on and defini�on are done in some
other file such as func. c. During the compila�on, the compiler finds the
sub() func�on in func.c file, so it generates two object files, i.e., main. o
and func. o. At the execu�on �me, if the defini�on of sub() func�on is
not found in the func�on.o file, then the linker error will be thrown. The
most common linker error that occurs is that we use Main() instead of
main().

Let's understand through a simple example.

Output
Logical error

A logical error is an error that leads to an undesired output. These


errors produce incorrect output, but they are error-free, known as
logical errors. The occurrence of these errors mainly depends upon the
logical thinking of the developer.

Let's understand through an example.

Output
Semantic error

Seman�c errors are the errors that occur when the statements are not
understandable by the compiler.

The following can be the cases for the seman�c error:


• Use of a un-ini�alized variable.
int i;
i=i+2;
• Type compa�bility
int b = "javatpoint";
• Errors in expressions
int a, b, c;
a+b = c;
• Array index out of bound
int a[10];
a[10] = 34;

Let's understand through an example.

In the above code, we use the statement a+b =c, which is incorrect as
we cannot use the two operands on the le�-side.
Output

Ahmed Mostafa

You might also like