What is the difference between compile error and runtime error? | Sololearn: Learn to code for FREE!

+4

What is the difference between compile error and runtime error?

programming coding

c# c++ c

4 Answers

New Answer

+22

A compiler error will prevent your code from running at all as it cannot successfully complete compilation. These are usually syntax errors, file reference errors, etc. Runtime errors aren't caught until the program is running. They prevent your code from completing execution. Examples include division by zero, memory violations, reference to null, etc.

+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...