EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Types of Errors in C

Home » Software Development » Software Development Tutorials » C Programming Tutorial » Types of Errors in C

Types of Errors in C

Introduction to Types of Errors in C

Errors in C language is defined as an illegal operation performed by the user which will result in the abnormal or abrupt working of the program logic. Programming errors are unidentified until the program is compiled or executed. Some of the errors in C are hidden or prevent the program from compiled or executed. So while we are executing our application successfully we must remove the errors from the program.

Real Time Scenario: We have an application for displaying sum of the numbers while declaring variables we have missed semi colon or wrong syntax of the main method resultinto error while executing the application.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Advantage:

  • Before compilation, we will eliminate all error issues.

Types of Errors in C

C language broadly classified errors into 5 types. They are

Types of Errors in C

1. Syntax Errors

Errors occur when you violate the rules of writing C syntax is said to be “Syntax errors”. This compiler error indicates that this must be fixed before the code will be compiled. These errors are identified by the compiler so these errors are called “compile-time errors”.

Syntax:

a. void main()
{
int a //here semi colon(;)missed
}
b. void main()
{
int a;
//here parenthesis(}) missed

2. Run-Time Errors

Errors which are occurred after a successful compilation of program is said to be “run-time errors”. Number divisible by zero, array index out of bounds, string index out of bounds, etc. are most frequent run-time errors. These errors can’t be very hard to detect at the compile time.

Popular Course in this category
C Programming Training (3 Courses, 5 Project)3 Online Courses | 5 Hands-on Projects | 34+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,570 ratings)
Course Price

View Course

Related Courses
C++ Training (4 Courses, 5 Projects, 4 Quizzes)Java Training (40 Courses, 29 Projects, 4 Quizzes)

Syntax:

a. void main()
{
int a=10;
int c=a/0;// Here number divisible zero error occurs
}
b. void main()
{
int a[3]={1,2,3};
int out=a[4];// Here array out of bounds error occurs
}

3. Linker Errors

These errors are generated after compilation we link the different object files with the main’s object using the Ctrl+F9 short cut key. These errors occurred when the executable program cannot be generated. This may be due occurred because of wrong function declaration, importing incorrect header files, etc. Most frequent linkererror is writing Main() instead of a main() method.

Syntax:

void Main() // Here Main() method used instead of main() method
{
}

4. Logical Errors

If our expectation is one thing and result output is other thing then that kind of error we said it as “Logical errors”. Let suppose if we want sum of the 2 numbers but given output is the multiplication of 2 numbers then this said to be Logical error. It can be detected by line by line debugging.

Syntax:

void Main()
{
printf("%d",sum(10,20));
}
int sum(int a, int b)
{
return x*y;//expectation is sum but we are multiplying the numbers
}

5. Sematic Errors

This error generated if and only if written code is not understandable format to the C compiler.

Syntax:

void main()
{
int x, y, z;
x + y = z; //semantic error }

Examples of Types of Errors in C

Following are the examples are give below:

1. Syntax Error with Semicolon Example

Code:

#include<stdio.h> //Used to include basic c library files
void main() //Used to execute the C application
{
//declaring and defining the variables
int x = 10;
int y = 15;
//displaying the output
printf("%d", (x, y)) //Here semi-colon missed
}

Output:

Types of Errors in C-1.1

2. Syntax Error with Mustache Brace Example

Code:

#include<stdio.h> //Used to include basic c library files
void main() //Used to execute the C application
{
//declaring and defining the variables
int a = 100;
int b = 105;
//displaying the output
printf("%d %d",a,b);
//Here mustache brace missed

Output:

Types of Errors in C-1.1

3. Run-Time Errors with Array Index out of Bounds Example

Code:

#include<stdio.h> //Used to include basic c library files
void main() //Used to execute the C application
{
//declaring and defining the array variables
int a[5] = {100,101,102,103,104};
int b[5] = {105,106,107,108,109};
//displaying the output
printf("%d\n",a[100]); //array index out of bounds run-time error
//in c this is not shown any error message it will just show out of bound values as 0
printf("%d\n",b[700]);//array index out of bounds run-time error
}

Output:

Types of Errors in C-1.3

4. Run Time Error with Zero Divisible by Number Example

Code:

#include<stdio.h> //Used to include basic c library files
void main() //Used to execute the C application
{
//declaring and defining the variables
int x = 200;
int y = 400;
int a=x/10;
int b=y/0;
//displaying the output
printf("%d\n",a); // Here no divisible by zero error occurs
printf("%d\n",b); //divi by zero run time error
}

Output:

Types of Errors in C-1.4

5. Linker Error with Wrong Main() Method Syntax Example

Code:

#include<stdio.h> //Used to include basic c library files
void Main() //Linker error as wrong syntax of main method used
{
//declaring and defining the array variables
char a[] = "Amardeep";
char c[] = "Paramesh";
//displaying the output
printf("%s\n",a);
printf("%s\n",c);
}

Output:

Output-1.5

6. Logical Error Example

Code:

#include<stdio.h> //Used to include basic c library files
int sum(int a, int b);// Including method
void main()//main() method for executing the application
{
//declaring and defining the variables
int a=100;
int b=200;
//displaying the output
printf("Sum of %d and %d is=%d\n",a,b,sum(a,b));//sum(a,b) is calling method
}
//called method
int sum(int a, int b)
{
return a*b;//instead of sum here developer make a mistake by return multiplication logic
}

Output:

Output-1.6

7. Sematic Error Example

Code:

#include<stdio.h> //Used to include basic c library files
void main() //main() method for executing the application
{
//declaring and defining the variables
int a=100;
int b=200;
int a+b=c;//sematic error by unkwoning c language code
//displaying the output
printf("%d %d",a,b);
}

Output:

Output-1.7

Conclusion

Errors in C language are occurred due to writing understandable statements passed to a compiler then the compiler throws some errors. These errors can be programmer mistakes or sometimes machine insufficient memory to load the code. Errors are mainly 5 types that are Syntax errors, Run-time errors, Linker errors, Logical errors, and Logical errors.

Recommended Articles

This is a guide to Types of Errors in C. Here we also discuss the Introduction and types of errors in c along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. Timer in C#
  2. Double Pointer in C
  3. Void Pointer in C
  4. Stderr in C

C Programming Training (3 Courses, 5 Project)

3 Online Courses

5 Hands-on Projects

34+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
C Programming Tutorial
  • Advanced
    • Constructor in C
    • Encapsulation in C
    • C Storage Classes
    • Static Keyword in C
    • File Handling in C
    • Queue in C
    • Hexadecimal in C 
    • typedef in C
    • Memory Allocation in C
    • Linked List in C
    • Volatile in C
    • Tokens in C
    • Expression in C
    • Regular Expression in C
    • Error Handling in C
    • Types of Errors in C
    • Preprocessor in C
    • Preprocessor Directives in C
    • fscanf() in C
    • #Pragma in C
    • #ifndef in C
    • #undef in C
    • Macros in C
  • Basic
    • Introduction to C
    • What is C
    • Career in C Programming
    • Advantages of C
    • How to Install C
    • Best C Compilers
    • Data Types in C
    • Variables in C
    • C Keywords
    • C Command
    • Command Line Arguments in C
    • C Literals
    • Constants in C
    • Unsigned Int in C
    • String in C
  • Pointers
    • Pointers in C
    • Null pointer in C
    • Function Pointer in C
    • Double Pointer in C
    • Void Pointer in C
    • Const Pointer in C
    • Dangling Pointers in C
    • Pointer Arithmetic in C
  • Operators
    • C Operators
    • Arithmetic Operators in C
    • Relational Operators in C
    • Assignment Operators in C
    • Logical Operators in C
    • Conditional Operator in C
    • Modulus Operator in C
    • Ternary Operator in C
    • Address Operator in C
    • Unary Operator in C
    • Operators Precedence in C
    • Left Shift Operator in C
  • Control Statement
    • Control Statements in C
    • If Statement in C
    • If-else Statement in C
    • Else if Statement in C
    • Nested if Statement in C
    • #else in C
    • Structure Padding in C
    • Nested Structure in C
    • Continue Statement in C
    • Break Statement in C
    • Switch Statement in C
    • Goto Statement in C
  • Loops
    • Loops in C
    • For Loop in C
    • While Loop in C
    • Do While Loop in C
    • Nested Loop in C
    • Infinite Loop in C 
  • Function
    • Math Functions in C
    • Hashing Function in C
    • Recursive Function in C
    • Power Function in C
    • fputs in C
    • C puts() Function
    • fprintf() in C
    • fseek() in C
    • Stderr in C
    • ASCII Value in C
    • strcat() in C
    • Inline Function in C
    • sizeof() in C
    • Function Prototype in C
    • C ftell()
  • Array
    • Arrays in C Programming
    • 2-D Arrays in C
    • 3D Arrays in C
    • Multidimensional Array in C
    • Array Functions in C
    • Strings Array in C
  • Sorting
    • Sorting in C
    • Heap Sort in C
  • C programs
    • Patterns in C Programming
    • Star Patterns in C
    • Number Patterns in C
    • Swapping in C
    • Reverse Number in C
    • Palindrome in C Program
    • Factorial in C
    • Fibonacci Series in C
    • Square Root in C
    • Random Number Generator in C
    • Prime Numbers in C
    • Escape Sequence in C
    • Reverse String in C
    • Leap Year Program in C
    • Anagram Program in C
    • Strong Number in C
    • String Concatenation in C
    • C Programming Matrix Multiplication
    • Decimal to Octal in C
    • Expression Evaluation in C
    • Decimal to Hexadecimal in C
  • Interview question
    • C Programming Interview Questions

Related Courses

C Programming Training Course

C++ Training Course

Java Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - C Programming Training (3 Courses, 5 Project) Learn More