+ 4
What is the difference between compile error and runtime error?
programming coding
5 Réponses
+ 6
>> While if you are COMPILE your program and then you get error it's compile error.
and
>> if You are RUN your program and then you get error so it's Run time error.
+ 3
As Luka said, just adding on some examples:
Compile time like when you compile a program with syntax error.
Run time like when you try to store a string into a int.
0
1)Compile-Time Errors: Errors that occur when you violate the rules of writing syntax are known as Compile-Time errors. This compiler error indicates something that must be fixed before the code can be compiled. All these errors are detected by the compiler and thus are known as compile-time errors.
Most frequent Compile-Time errors are:
-->Missing Parenthesis (})
-->Printing the value of variable without declaring it
-->Missing semicolon (terminator)
Below is an example to demonstrate Compile-Time Error:
// C program to illustrate
// syntax error
#include<stdio.h>
void main()
{
int x = 10;
int y = 15;
// semicolon missed
printf("%d", (x, y))
}
2)Run-Time Errors: Errors which occur during program execution(run-time) after successful compilation are called run-time errors. One of the most common run-time error is division by zero also known as Division error. These types of error are hard to find as the compiler doesn’t point to the line at which the error occurs.
For more understanding run the example given below.
// C program to illustrate
// run-time error
#include<stdio.h>
void main()
{
int n = 9, div = 0;
// wrong logic
// number is divided by 0,
// so this program abnormally terminates
div = n/0;
printf("resut = %d", div);
}
Hope this will help you...
0
A compile-time error generally refers to the errors that correspond to the semantics or syntax. A runtime error refers to the error that we encounter during the code execution during runtime. We can easily fix a compile-time error during the development of code. A compiler cannot identify a runtime error.