×

Errors in C

Errors in C

Errors are nothing but problems or faults that pretty much occur in all the programming languages. Errors make the behavior of the program seem abnormal, and even the experienced programmer makes one. Programming errors are also referred to as bugs or faults, and removing these errors is termed debugging.

It is an illegal operation that a developer performs, which leads to the abnormal working conditions of that program. Errors remain unnoticed until and unless the compiler compiles or is executed by the runtime. Many errors exhibit the program from getting compiled and executed. Hence, they have to debug for smooth compiling and executing.

Errors lead to the abrupt and illegal operation of the logic of the program. Many errors in the C programming language are hidden and prevented from the program from compilation or execution. Hence, while executing any application, for that matter, one should successfully take out the errors present within the program.

Consider an instance where a program has been written to display the product of two numbers. But while defining the variables, a programmer forgets to put the semicolon at the end, which results in an error while compiling. Hence, they are either identified during compilation or execution.

Types of Error in C

There are five types of errors that exist in the C standard:

Syntax error

  1. These types of errors when the program or an application violates the rule of the programming standard.
  2. Syntax errors also known as the compilation errors as they occur at the compilation time or the syntax errors since they are thrown by the compilers.
  3. These are the errors that mainly occur due to the mistakes while typing down the code or not following the syntax according to the C standard.
  4. They are usually done by the beginners as they may be new to the programming language.
  5. They can be debugged easily and rewritten.

E.g.:

 int x;
 Int x; 

The above-mentioned syntax is different from each other and the latter gives the syntax error due to case sensitivity.

Common errors in these types include;

  • Missing semicolon at the end of the code.
  • Displaying value without any declaration.
  • Missing parentheses.
  • Case sensitivity.
 #include <stdio.h>
 #include <conio.h>
 int main()
 {
 x = 10;
 printf (“The value of a is: %d”, a);
 return 0;
 } 

Output:

Errors in C

Runtime error

  • Errors that occur at the time of execution of a program or a runtime after successful compilation are referred to as runtime errors.
  • One of the most common runtime errors occur when a number is divided by zero also known as division error.
  • These are the types of errors which are pretty hard to guess as the compiler does not point where the actual error occurs.

E.g.:

 #include<stdio.h>
 void main()
 {
 int n = 9, div = 0;
 div = n/0;
 printf("resut = %d", div);
 } 

Output:

Errors in C

Linker error

  • This type of errors is occurred when the program is compiled successfully, and trying to link the different objects file with the main object file.
  • Whenever this error is occurred, the executable is not generated such as wrong function prototyping, incorrect header files, and so on.
  • Whenever the main() function has case sensitivity issues, this error arouses.

E.g.:

 #include<stdio.h>
 main()
 {
 int x = 52;
 int y = 0;
 printf("Div : %f", x/y);
 } 

Output:

Errors in C

Logical error

  • A logical error is one of the types of error in the C language that arouses an undesired output.
  • They are error free but still give errors which are logical.
  • They occur when the errors depend upon the logical thinking of the developer.
  • If the programmers sound logically good, then there might be a fewer cases of these errors.

E.g.:

 #include<stdio.h>
 #include<conio.h>
 int main()
 {
 int sum = 0;
 int k = 1;
 for (int i = 1; i <= 10; i++);
 {
 sum = sum +k;
 k++;
 }
 printf (“The value of the sum is %d”, sum);
 return 0;
 } 

Output:

Errors in C

In the above code snippet, a for loop has a semicolon hence the inner loop will not execute and produces the output as 1.

Semantic error

  • It is the type of error that occurs when it syntactically is correct but have no meaning.
  • If an expression is given at the left side of the assignment operator, then it generates a semantic error.

E.g.:

 #include<stdio.h>
 int main()
 {
 int a, b, c;
 a = 10;
 b = 20;
 a + b = c;
 } 

The following can be the cases for the semantic error:

  • Use of a un-initialized variable.
    int i;
    i = i+2;
  • Type compatibility
    int b = "tutorials and examples";
  • Errors in expressions
    int a, b, c;
    a+b = c;
  • Array index out of bound
    int a[10];
    a[10] = 34;

Related Topics

Runtime vs compile time in C

In the C programming language, the often used terms in every step consist of compile time and runtime. The compile time is referred to the source code that will be...

4 minutes read.

Random Access - Lseek in C

Introduction lseek is a system call that is used to alter the location of the read/write pointer of a file descriptor. The lseek system call basically moves the current read/write location...

4 minutes read.

Pointer arithmetic in C

In the C programming language, a pointer is an address which stores a numeric value. Hence, a developer can perform several arithmetic operations on the same just as one does...

4 minutes read.

Float in islower() in C

Introduction: This article briefly discusses the float in islower() in C. The islower() function checks if the input character passed inside the function is lowercase. Lowercase letters include (a-z). The islower()...

4 minutes read.

Sum of N numbers in C using For loop

Before we move on the program of sum of N numbers, first we have to know about the For Loop statement. The syntax of ‘for’ loop in C programming language is...

3 minutes read.

How to move a text in C

A text can be moved to the desired location in the output based on the coordinates provided in the gotoxy() function. What is gotoxy() function? In C language, gotoxy() is a pre-defined...

3 minutes read.

Run Time Polymorphism in C

What is polymorphism? Polymorphism refers to the existence of various forms. Polymorphism can be simply defined as a message's capacity to be presented in multiple forms. An individual who can have...

4 minutes read.

Calloc in C

The calloc() is a library function in C which is used for memory allocation. The calloc() function dynamically allocates multiple blocks of memory to complex data structures. This includes data structures...

3 minutes read.

Break, continue and goto statement in C

Break statement Break statement is used to break the process of a loop (while, do while and for) and switch case. Syntax: break; Example 1 while(test Expression) { // codes if(condition for break){ break; } // codes } Example 2 For(int it, condition,...

1 minute read.

If Statement in C

Decision Control Statements We frequently desire one set of instructions to be carried out in one circumstance while another set of instructions to be carried out in a completely different circumstance....

3 minutes read.

Malloc function in C

When the user or programmer does not know how much memory space is needed in the application, it a needs dynamic memory allocation during runtime. Dynamic memory allocation helps us to...

4 minutes read.

While Loop in C programming examples

Introduction There is always a header file containing all the essential data regarding inputs and outputs of various functions in the C programs. The following statement describes how to use/add header file...

22 minutes read.

Deadlock Detection Program in C

What is Deadlock? A deadlock is a circumstance where a group in the process is halted because they are each holding onto resources while waiting for other methods to obtain them. Think...

5 minutes read.

Multiplication Table in C

Displaying table up to 10 #include <stdio.h> int main() {     int num, i = 1;     printf("     Enter any Number:");     scanf("%d", &num);     printf("Multiplication table of %d: ", num);  ...

1 minute read.

C and C++ Binary Files

What is a binary file? A file in which the content is written in binary format is called a binary file. A binary file is not a text file. There are...

7 minutes read.

Bigint (BIG INTEGERS) in C with Example

The maximum number of digits that a long, long int can have in C/C++ is 20. The issue is how to store the 22-digit number, which is difficult to do...

9 minutes read.

Exponential() in C

Introduction: In C language, there are available many types of functions. The exponential() function is one of them. It is a mathematical function. This article describes using the pow() property to...

3 minutes read.

Factorial Program in C using For Loop

Before move on the factorial program. We have to know about the for loop in C programming language. The syntax of the For Loop is: for (initialization statement; test expression; an increment...

3 minutes read.

Typedef vs define in C

Typedef VS define in C Typedef In the C programming language, a keyword called typedef can be used to give a type a new name. In other words, it is used to...

5 minutes read.

Union Program in C

 How should a union be defined?  In C programming, a Union is a method used to organize different data types into groups in the same way that Structures are used. We...

4 minutes read.