The Wayback Machine - https://web.archive.org/web/20241001141851/https://www.geeksforgeeks.org/difference-between-compile-time-errors-and-runtime-errors/
Open In App

Difference between Compile Time Errors and Runtime Errors

Last Updated : 21 Sep, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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




// C++ program to illustrate
// syntax error
#include <iostream>
using namespace std;
 
int main()
{
    int x = 10;
    int y = 15;
     
// semicolon missed
    cout << " "<< (x, y)
}


C




// C program to illustrate
// syntax error
 
#include<stdio.h>
 
void main()
{
    int x = 10;
    int y = 15;
     
// semicolon missed
    printf("%d", (x, y));
}


Java




// Java program to illustrate
// syntax error
 
import java.io.*;
 
class GFG {
    public static void main (String[] args) {
    int x = 10;
    int y = 15;
     
    // semicolon missed
    System.out.println(x+y)
    }
}


Error: 

error: expected ';' before '}' token

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




// C++ program to illustrate
// run-time error
 
#include <iostream>
using namespace std;
 
int main()
{
    int n = 9, div = 0;
   
    // wrong logic
    // number is divided by 0,
    // so this program abnormally terminates
    div = n/0;
     
    cout <<"result = " << div;
}


C




// 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("result = %d", div);
}


Java




// Java program to illustrate
// run-time error
import java.io.*;
 
class GFG {
    public static void main (String[] args) {
       int n = 9, div = 0;
   
      // wrong logic
      // number is divided by 0,
      // so this program abnormally terminates
      div = n/0;
 
      System.out.print(" result = "+ div);
    }
}


Error: 
 

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

In the given example, there is Division by zero error. This is an example of run-time error i.e errors occurring while running the program.

The Differences between Compile-Time and Run-Time Error are:

Compile-Time Errors Runtime-Errors
These are the syntax errors which are detected by the compiler. These are the errors which are not detected by the compiler and produce wrong results.
They prevent the code from running as it detects some syntax errors. They prevent the code from complete execution.
It includes syntax errors such as missing of semicolon(;), misspelling of keywords and identifiers etc. It includes errors such as dividing a number by zero, finding square root of a negative number etc.

 



Similar Reads

Difference between runtime exception and compile time exception in PHP
The term PHP is an acronym for Hypertext Preprocessor, which is a server-side scripting language designed specifically for web development. It is open-source which means it is free to download and use. It is very simple to learn and use. The files have the extension “.php”. It is an interpreted language and it does not require a compiler. PHP code
3 min read
Difference between Compile Time and Execution Time address binding
Prerequisite - Address Binding Methods Address Binding is the association of program instructions and data to the actual physical memory location. There are various types of address binding in the operating system. There are 3 types of Address Binding: Compile Time Address Binding Load Time Address Binding Execution Time Address Binding Here, we co
2 min read
Difference between Compile-time and Run-time Polymorphism in Java
The word polymorphism means having many forms. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. In this article, we will see the difference between two types of polymorphisms, compile time and run time. Compile Time Polymorphism: Whenever an object is bound with its functionality at the
3 min read
Difference Between Compile Time and Load Time Address Binding
Address binding is a situation whereby one address is linked to another in computer systems. This mapping can also happen at different times during program execution they may be compile-time, load-time, or run-time Knowing the differences between these types of address binding is important to comprehend the process of memory management and program
4 min read
Runtime Errors
Runtime Errors:A runtime error in a program is an error that occurs while the program is running after being successfully compiled.Runtime errors are commonly called referred to as "bugs" and are often found during the debugging process before the software is released.When runtime errors occur after a program has been distributed to the public, dev
7 min read
Difference between link and compile in AngularJS
In this article, we will see the link and compile features in Angular JS, along with understanding their implementation through the illustration and exploring the key differences between them. One of the fundamental components of AngularJS is the directive. When creating web components, a directive enables declarative HTML vocabulary expansion. Att
5 min read
Time difference between expected time and given time
Given the initial clock time h1:m1 and the present clock time h2:m2, denoting hour and minutes in 24-hours clock format. The present clock time h2:m2 may or may not be correct. Also given a variable K which denotes the number of hours passed. The task is to calculate the delay in seconds i.e. time difference between expected time and given time. Ex
5 min read
How to avoid Compile Error while defining Variables
Variables: A variable is the name given to a memory location. It is the basic unit of storage in a program. The value stored in a variable can be changed during program execution. A variable is only a name given to a memory location, all the operations done on the variable effects that memory location. All the variables must be declared before use.
3 min read
Difference between Time Tracking and Time and Attendance Software
Time tracking and time and attendance software are tools that help businesses track the time that employees spend on tasks and their attendance records. These tools can help businesses automate their time tracking processes, reduce errors and inaccuracies, and ensure that employees are paid accurately for the time they work. Time tracking software
4 min read
Difference between Time Sharing OS and Real-Time OS
Prerequisite - Types of Operating Systems Time sharing operating system allows concurrent execution of programs through rapid switching thereby giving each process the same amount of time to execute. In this operating system Switching method/function is available. This switching is incredibly quick in order that the users will be able to execute th
2 min read
Difference between Seek Time and Disk Access Time in Disk Scheduling
Seek Time: A disk is divided into many circular tracks. Seek Time is defined as the time required by the read/write head to move from one track to another. Example, Consider the following diagram, the read/write head is currently on track 1. Now, on the next read/write request, we may want to read data from Track 4, in this case, our read/write hea
3 min read
Difference between Transfer Time and Disk Access Time in Disk Scheduling
1. Transfer Time : Time required to transfer the required amount of data. It can be calculated by the given formula Transfer time, = Data to be transfer / transfer rate Data to be transfer is given in the question and transfer rate is sometimes given and sometimes it may not be given. It can be calculated by the given formula. Transfer Rate, = {(Nu
2 min read
Difference between Real-time Tasks and Non-Real-time Tasks
1. Real-time Tasks : Real-time tasks are the tasks associated with the quantitative expression of time. This quantitative expression of time describes the behavior of the real-time tasks. Real-time tasks are scheduled to finish all the computation events involved in it into timing constraint. The timing constraint related to the real-time tasks is
2 min read
Difference between Firm Real-time Tasks and Soft Real-time Tasks
Real-time tasks are generally classified as - Hard and Soft but on a wide range, Real-time tasks are classified as: Hard Real-time TasksFirm Real-time TasksSoft Real-time Tasks 1. Firm Real-time Tasks : Firm real-time tasks are such type of real-time tasks which are associated with time bound and the task need to produce the result within the deadl
2 min read
Difference between Time and Attendance vs Time Billing Software
1. Time and Attendance Software : Time and Attendance software allows one to keep track of all employees that are coming and going out as well as their break time, time related needs, etc. 2. Time Billing Software : Time Billing Software allows one to track time being spent on projects so that bill can be created according to this. It simple manage
2 min read
Difference between Round trip time (RTT) and Time to live (TTL)
1. Round Trip Time (RTT) :The length of time taken by a data packet to be sent to a destination including the time it takes for an acknowledgement of that packet to be received back at the origin place. 2. Time to live (TTL) :The lifespan or life time of data that is being sent. Once after that specified time is over or elapsed the data will be dis
3 min read
Difference Between Central Time and Mountain Time
Central Time and Mountain Time are two of the six time zones in the United States, each with its own unique characteristics and features that are important to understand. Central Time is used in the central region of the United States, including states such as Illinois, Wisconsin, Missouri, and Iowa, and parts of Texas, Kansas, and Nebraska. This t
5 min read
Difference Between Seek Time and Transfer Time in Disk Scheduling
The head's seek time is the time it takes to move from the current track to the one containing the data. The amount of time needed to move data from the disc to the host system is called the transfer time. In hard drives, a head is present which is supposed to write or read from the magnetic disk. In this article we are going to discuss what are se
4 min read
Difference between Load Time and Execution Time address binding
Prerequisite - Address Binding Methods Address Binding is the association of program instructions and data to the actual physical memory location. There are various types of address binding in the operating system. There are 3 types of Address Binding: Compile Time Address Binding Load Time Address Binding Execution Time Address Binding Here, we co
2 min read
Difference Between Arrival Time and Burst Time in CPU Scheduling
In CPU scheduling, there are two important terms called as “Arrival Time” and “Burst Time.” These two terms play a key role in understanding the way processes are managed in the operating system and specifically, when the CPU time is to be allocated towards different tasks. By knowing the difference between Arrival Time and Burst Time one is indeed
4 min read
Difference Between Turn Around Time (TAT) and Waiting Time (WT) in CPU Scheduling
As for the evaluation of the performance of various algorithms in CPU scheduling, Turn Around Time (TAT) and Waiting Time (WT) used as measurement criteria. These two metrics are important because they define the effectiveness with which the processes go through a system. Turn Around Time means the total amount of time taken from the initiation of
5 min read
Difference Between Mountain Time and Eastern Time
The United States is divided into six standard time zones: Pacific, Mountain, Central, Eastern, Alaska, and Hawaii-Aleutian. The difference between Mountain Time and Eastern Time is one hour. Mountain Time is two hours behind Pacific Time and one hour ahead of Central Time, while Eastern Time zone is one hour ahead of Central Time and one hour behi
5 min read
Difference Between Hard Real Time and Soft Real Time System
In computer science, real-time systems are an intrinsic component of applications with high demands on time, for input processing. According to their response to time constraints, there are two categories as follows Hard Real-Time Systems and Soft Real-Time Systems. Even though both systems have deadlines to be met it is the consequences of failure
6 min read
Difference between Rotational Latency and Transfer Time in Disk Scheduling
1. Rotational Latency: Rotational Latency is the amount of time it takes for the desired sector of a to rotate under the read-write heads of the disk drive. In other words, the disk is divided into many circular tracks, and these tracks are further divided into blocks knows as sectors. So Rotational Latency is the time required by the read/write he
2 min read
Difference between Periodic and Aperiodic Real-time Tasks
1. Periodic Real-time Tasks : The real-time task that is repeated after a certain time interval is known as periodic real-time task. Basically the periodic real-time tasks are controlled by the clock interrupts. Therefore, the periodic real-time tasks are also called clock-driven tasks. The time interval after which the task repeats itself is known
2 min read
Difference between Periodic and Sporadic Real-time Tasks
Prerequisite - Tasks in Real Time systems 1. Periodic Real-time Tasks : The real-time task that is repeated after a certain time interval is known as periodic real-time task. Basically the periodic real-time tasks are controlled by the clock interrupts. Therefore, the periodic real-time tasks are also called clock-driven tasks. For example, in a ch
2 min read
Difference between Relative and Absolute Deadline of Real-time Task
1. Relative Deadline : The time interval between the start of the task and the completion of the real-time task is known as Relative deadline. It is basically the time interval between arrival and corresponding deadline of the real-time task. If the arrival time of task is 't' and corresponding deadline of task is 't+d' then, Relative deadline = d
2 min read
Difference between Sporadic and Aperiodic Real-time Tasks
There are two types of tasks in real-time systems: Periodic tasks, and Dynamic tasks. Further Dynamic Tasks are classified as: 1. Sporadic Real-time Tasks : The real-time tasks that reoccur at any random instant and have hard deadline are known as sporadic real-time tasks. Sporadic real-time tasks have some similarity to aperiodic real-time tasks b
2 min read
Difference between Delay and Deadline Constraint in Real-time System
Prerequisite - Timing Constraints in Real-time System 1. Delay Constraint : Delay constraint is the minimum time interval between occurrence of two consecutive events in the real-time system. If an event occurs before the delay constraint, then it is called a delay violation. The time interval between occurrence of two events should be greater than
2 min read
Difference between Rotational Latency and Disk Access Time in Disk Scheduling
1. Rotational Latency : Rotational Latency is also known as Rotational time. The amount of time taken by the disk to rotate the track when the read/write head come to exact sector or we can also say that the time taken by the desired sector to come under the read/write head is called rotational latency. Rotational Latency is depends on the rotation
4 min read