×

Runtime vs compile time in C

In the C programming language, the often used terms in every step consist of compile time and runtime. The compile time is referred to the source code that will be converted into an executable code; on the contrary, the runtime will be considered when the executable code starts running. Compile time and runtime differ in many ways, such as types of error and so on.

Compile time: It is referred to as a program’s time to compile the program followed by some operations. The operations are followed by a part of the step known as a compiler. The operations are done to convert the code written by a developer or a programmer in a particular programming language.

  • There is no need for a program to satisfy any variants. It needn’t be a well formed program.
  • Always keep an eye on syntax errors, type checking errors, compiler crashes (happens rarely) as they might lead to a bug further in the program.
  • If a compiler succeeds, then the program is well formed and is a meaningful program, and you can proceed to the next step, running the program.

Runtime: Before coining the term runtime, writers used the phrase “when a program is run”, and due to this repeated usage of the phrase came the word runtime. It is used to refer to a program when it is running. In a program life cycle, a program’s total time starting to run in the memory until the user or the operating system terminated the program is known as the runtime.

  • The runtime will not know about the program’s variants. Anything a programmer or a developer types in will be considered.
  • Runtime variants are rarely enforced by a compiler alone. It needs external help from the programmer.
  • Always keep an eye on errors such as division by zero, dereferencing a null pointer, and running out of memory.
  • There might be errors detected only by the program, such as trying to open a file that is not available and finding a web page that does not have a well formed URL (Uniform Resource Locator).
  • If a runtime succeeds, then the program is considered successful, and it finishes without any crashing.
  • Inputs and outputs are dependent upon a developer or a programmer. Files, windows on the screen, network packets, commands to a printer, anything a programmer wishes to do will happen if the program runs successfully.

Compile time errors:

Compile time errors are the errors that will occur when a programmer or a developer writes a wrong syntax. If we write the wrong syntax or semantics, then the compile-time errors will be thrown by the compiler. The compiler will not let the program run until all the errors are removed from the program. Once all the errors are removed from the program, then the compiler will generate the executable file.

Compile time errors include:

1. Syntax errors: when a developer does not follow the programming language’s syntax, the compiler will throw a syntax error.

E.g.:

#include <sdtio.h>
#include <conio.h>


int main()
{
int a = 4, b = 3, c:
c = a + b;
printf (“Sum is: %d \n”, c );
	return 0;
}

            In the above example, it can be seen that the declaration ends with a colon (:) instead of a semicolon (;), which is a syntax error.

2. Semantic errors: Semantic errors occur when the statements are not meaningful to the compiler.

E.g.:

#include <sdtio.h>
#include <conio.h>


int main()
{
int a = 4, b = 3, c:
a + b = c;
printf (“Sum is: %d \n”, c );
	return 0;
}

In the above example, the sentence ‘a + b = c’ throws a compile time error. In the above statement, the programmer assigns the value ‘c’ to the summation of  ‘a’ and ‘b’, which is not possible in the C programming language as it can contain only one variable on the left to the assignment operator while the right side of the operator can contain more than one variable.

Runtime errors:

These are errors that occur during the execution and after compilation. Some of the examples of runtime errors are division by zero, and so on. The errors are not easily detectable as the compiler does not point precisely to them.

Difference between compile time and runtime:

Compile timeRuntime
The compiler prevents the code from execution if the the compiler detects an error in the program.The compiler will not detect any error, and hence it cannot prevent the code from any execution happening further.
These are the errors that are produced at compile time and are detected by the compiler only.These are the errors which are not generated by the compiler and produce an unpredictable result at the execution time.
It contains the syntax and semantic errors like missing semicolon at the end of any statement.It may contain errors such as division by zero, determining the square root of any negative number.

Related Topics

One Dimensional Array in C

One Dimensional Array in C: In the C programming language, an array is defined as a collection of one or more values of the same type. Every value present in...

4 minutes read.

C Function Argument and Return Values

Functions in the C programming language are declared to avoid repeatedly writing a performable block of code; it is the same in any programming language. When it comes to the...

3 minutes read.

Storage class in C

Storage class in C defines the scope, the visibility, and the lifetime of variables and functions. In other words, storage classes are used to describe the features of variables and...

3 minutes read.

What is required in each C Program?

Each C program must require one function, i.e., main() function. It is because when we execute the C program, C compiler looks for the main() function, and from here only...

5 minutes read.

How to use floor() function in C

Introduction: The floor() used as a function in the C programming language. This function uses to return the largest or most significant integer value. The integer value is smaller than...

3 minutes read.

C program to Store Information of Students Using Structure

What is the Structure in C? User-defined data types include structures. Structures aid your ability to combine things of various categories into a single group. Like arrays, it operates similarly. A...

3 minutes read.

Bank Account System in C using File Handling

This tells about the creation of bank account system using the C language and handling of files in C. Approach Let us see the approaches and the functions how they are covering...

5 minutes read.

Infinite loop in C

Definition of infinite loop The infinite loop is a loop that does not get dismissed because of its looping construct. A continuous output or no output are the two possible outcomes...

3 minutes read.

Assert() Function in C

Assert (): In C, the statements are executed with the exit statement. In C language declare, and it tests the condition parameters. If the statement executed will be false, it...

3 minutes read.

Multithreading in C interview questions

Q1. What exactly is a thread? Ans: A thread is a brief sequence of instructions intended to be planned and carried out by the CPU apart from the parent process. Q2. Can...

4 minutes read.

Round Robin Scheduling in C

Round Robin Scheduling in C Round robin is a CPU (Central Processing Unit) scheduling algorithm designed to share the time systems. It is one of the simplest and easiest scheduling algorithms...

4 minutes read.

Pointer to pointer in C

A pointer to another pointer is another type of multiple indirections and a chain of many pointers. Generally, a pointer consists of the address of the variable. Once a pointer to...

4 minutes read.

Macros in C

In the C programming language, the macro is defined as a segment of the code replaced by the macro defined value at the beginning. ‘#define’ is the directive that defines...

3 minutes read.

Two-Dimensional array in C

What is an Array? The collection of a fixed number of elements of homogeneous data types that are stored in contiguous locations in the memory is known as an array. Only...

6 minutes read.

Tower of Hanoi in C

What is Tower of Hanoi? The Tower of Hanoi is a gaming problem that was created in 1883 by a French mathematician named Édouard Lucas. The Tower of Hanoi temple in...

4 minutes read.

Flow Chart of Do while loop in C

This is a flowchart that represents the process of executing the Do while loop in the C programming language Generally, as we know there are three main components of Do While...

3 minutes read.

fork() in C

Introduction To create a new function in the system, there is a need for a system call, i.e. fork system call. It is also known as the child process. These child...

2 minutes read.

Dangling pointers in C

Dangling pointers in C: A pointer is a variable that stores the memory address of other variables. The pointers may also store the address of other’s memory items. They are...

4 minutes read.

C Program for Mean and Median of an Unsorted Array

In this tutorial, we will look at how to determine the mean and median of a given unsorted array. To determine the Mean: To get the average, mean is determined. The formula...

2 minutes read.

Comma Operator in C

What is a comma operator? The comma operator in the C programming language has the least priority. The comma operator is essentially a binary operator that operates on the first operand...

4 minutes read.