Home >Backend Development >C++ >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. |
CompileDemo.c
#include<stdio.h> public class CompileDemo{ void main(){ int x = 100; int y = 155; // semicolon missed printf("%d", (x, y)) } }
error: expected ';' before '}' token
RuntimeDemo.c
include<stdio.h> public class RuntimeDemo{ void main(){ int n = 9; div = 0; div = n/0; printf("resut = %d", div); } }
warning: division by zero [-Wdiv-by-zero] div = n/0;
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!