Programming Error

Some of the errors refuse the program from getting compiled or executed.Those errors are always detected either during the time of compilation or execution.Thus errors are removed before compiling and executing.

There are mainly five types error are detected in C programming language:

  • Syntax error
  • Run-time error
  • Linker error
  • Logical error
  • Semantic error
  • Syntax error: Syntax error are also known as compilation error and then they are only comes at the compile time.
    Compiler error indicates something because that they must be fixed before the code can be compiled.
    Most conman syntax error are:

    • Missing Parenthesis (})
    • Printing the value of without declaring it
    • Missing semicolon

    For Example:

    #include<stdio.h>
    void main()
    {
    int x = 15;
    int y = 12;
    
    printf("%d" ,(x,v))   //semicolon missed
    }

      Error

    error: expected ';' before '}' token

     

  • Run-time error: Errors exist during the execution time after successful compilation are called run-time errors.Program is running and we are not able to perform the operation is the main cause of the run-time errors.The most common run-time error is division by zero are also known as division error.

    You can understand these examples better after seeing

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

    Error

    warning: division by zero [-Wdiv-by-zero]
         n = m/0;
  • Linker error: Linker errors are mainly shown when the executable file of the program is not created.Thus error occurs when after compilation we link the different object file with main’s object.This are wrong functions prototyping, incorrect header files.The most common linker error is Main() instead of main().

    Let’s understand through a simple example

    #include <stdio.h>  
    int Main()  
    {  
        int a=23;  
        printf("The value of a is : %d", a);  
        return 0;  
    }

    Error

    (.text+0x20): undefined reference to `main'
  • Logical error: In those logical errors compilation and execution of a program desired output is not obtained when certain input values are given.
    These are one of the most common errors done by beginners of programming.These errors are mainly depends upon the logical thinking of the developer.

    Let’s understand through an example:

    #include <stdio.h>  
    int main()  
    {  
       int sum=0;  
       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;  
    }

    Output

    The value of sum is 1

    In the above code we are trying to print the sum of 10 digit , but we got the wrong output as we put the semicolon (;)
    after the for loop, so the inner statements of the for loop will not execute. This produces the wrong output.

  • Semantic error: Thus error occurs when the statements are not understandable by the compiler.

    Let’s understand through the example

    #include <stdio.h>  
    int main()  
    {  
    int a,b,c;  
    a=1;  
    b=2;  
    c=3;  
    a+b=c; // semantic error  
    return 0;  
    }

    Output

    error: lvalue required as left operand of assignment
     a + b = c; //semantic error

Submit your review
1
2
3
4
5
Submit
     
Cancel

Create your own review

The Technical Funda
Average rating:  
 0 reviews