Contents
Compile time vs Runtime
Compile time and runtime are two programming concepts used in software development. Compile time is the time when code is converted into executable code; Execution time is the time when the executable code starts running. Both involve time and effort to represent different types of errors.
Compile-time errors
Compile-time errors are errors that occur when we write the wrong syntax. If we mistype the syntax or semantics of a programming language, the compiler will throw a compile-time error. The compiler will not allow the program to run until all errors in the program are fixed. When all errors in the program are resolved, the compiler will create an executable file.
The compile-time errors can be:
- Syntax errors
- Semantic errors
-
Syntax errors
When a programmer does not follow the syntax of a programming language, the compiler will throw a syntax error.
Example
int x, y:
The above expression will produce the same error time as in C, each expression ends with a semicolon, but we put a colon (:) at the end of the expression
-
Semantic errors
A semantic error occurs when an expression fails the compiler.
example,
x+y=z;
The above expression will reflect the error of time. In the above expression, we have assigned the value “z” to the equation “x” and “y”, which is the only variable that cannot be done in C programming language because the left side of the operator, the right side of the operator can only have one variable of the operator. An employee’s job may be different.
The above statement can be re-written as:
z=x+y;
-
Run-time Errors
Runtime errors are errors that occur after execution and compilation. Examples of runtime errors are divided by zero and so on. These errors are difficult to identify because the compiler does not specify them.
Let’s examine some C error level errors, their conditions, and their consequences.
-
Division by Zero:
Since division by zero is undefined, attempting to divide a number by zero will cause a runtime error. This error may cause the program to crash or throw an exception.
Here is an example:
- #include <stdio.h>
- intmain()Â {
- int a = 10;
- int b = 0;
- int result = a / b; // Division by zero
- printf(“Result: %d\n”, result);
- return 0;
- }
Output
Floating point exception (core dumped)
differences between compile-time and runtime
Example of Compile-time error
- #include <stdio.h>
- intmain()
- {
- int a=20;
- printf(“The value of a is : %d”,a):
- return 0;
- }
Example of runtime error
- #include <stdio.h>
- intmain()
- {
- inta=20;
- intb=a/0; // division by zero
- printf(“The value of b is : %d”,b):
- return0;
}