Home > Backend Development > C++ > body text

In a C program, what is the difference between compile-time errors and run-time errors?

WBOY
Release: 2023-09-11 23:41:02
forward
1734 people have browsed it

In a C program, what is the difference between compile-time errors and run-time errors?

An error or exception is a situation where the expected result cannot be achieved due to an interruption in code execution. Depending on the event that generates or identifies the error, we can classify it into compile-time errors and run-time errors.

The following are the important differences between compile-time errors and run-time errors.

Serial number Key Compile time error Run time error
1 Reference Compile-time errors usually refer to errors related to syntax or semantics. On the other hand, runtime errors refer to errors encountered while executing code at runtime.
2 Detection Compile-time errors are detected by the compiler while the code is being developed. Run-time errors are not detected by the compiler and are therefore only recognized when the code is executed.
3 Fixation As mentioned before, compile-time errors can be fixed while the code is being developed. Run-time errors enter the repair state after the code is executed once and the error is recognized.

Examples of compile-time errors and run-time errors

CompileDemo.c

#include<stdio.h>
public class CompileDemo{
   void main(){
      int x = 100;
      int y = 155;
      // semicolon missed
      printf("%d", (x, y))
   }
}
Copy after login

Output

error: expected &#39;;&#39; before &#39;}&#39; token
Copy after login

Example

RuntimeDemo.c

include<stdio.h>
public class RuntimeDemo{
   void main(){
      int n = 9;
      div = 0;
      div = n/0;
      printf("resut = %d", div);
   }
}
Copy after login

Output

warning: division by zero [-Wdiv-by-zero]
div = n/0;
Copy after login

The above is the detailed content of In a C program, what is the difference between compile-time errors and run-time errors?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!