TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Wednesday, 6 May 2020

Programming Errors In C Language | Types Of Error in Programming With Example | Programming Error with Solution In C Langauge

Programming Errors In C Language

Errors are the problems or the faults that occur in the program, which makes the behavior of the program abnormal, and experienced developers can also make these faults.

 Programming errors are also known as the bugs or faults, and the process of removing these bugs is known as debugging.


These errors are detected either during the time of compilation or execution. Thus, the errors must be removed from the program for the successful execution of the program.

download image of type of programming error in c language

Fig: Programming Error In C Langauge 

There are mainly five types of errors exist in C programming:

  • Syntax error
  • Run-time error
  • Linker error
  • Logical error
  • Semantic error

1.Syntax error

Syntax errors are also known as the compilation errors as they occurred at the compilation time, or we can say that the syntax errors are thrown by the compilers. These errors are mainly occurred due to the mistakes while typing or do not follow the syntax of the specified programming language. 

 Program

#include <stdio.h>  

int main()  

{  

    a = 10;  
    printf("The value of a is : %d", a);  
   return 0;  
    }  
  

   Output:



download image of syntax error in c language

Fig: Syntax Error


2.Run-time error

Sometimes the errors exist during the execution-time even after the successful compilation known as run-time errors. When the program is running, and it is not able to perform the operation is the main cause of the run-time error. The division by zero is the common example of the run-time error. 

Program

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


Output:

download image of run time error in programming error in c language

Fig: Run-time Error

3.Linker error

Linker errors are mainly generated when the executable file of the program is not created. This can be happened either due to the wrong function prototyping or usage of the wrong header file.

Program

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

Output:

download image of linker error in c language

Fig: Linker Error In C Language  

4.Logical error

The logical error is an error that leads to an undesired output. These errors produce the incorrect output, but they are error-free, known as logical errors. 

Program

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

download image of logical error in c language

Fig: Logical Error In C Language 

5.Semantic error

Semantic errors are the errors that occurred when the statements are not understandable by the compiler.

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 = "dwivedicyberdairy";
  • Errors in expressions
    int a, b, c;
    a+b = c;
  • Array index out of bound
    int a[10];
    a[10] = 34;

Program

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

    Output:

download image Semantic Error In C Language

Fig: Semantic Error In C Language


 

No comments:

Post a Comment