×

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

Operators in C

An operator is a special symbol that tells the compiler to perform specific mathematical or logical operations. It is the combination of constants and variables through expressions. Example: int c = a+b*5 Where,...

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

Find Day from Day in C Without using function

Introduction: In the given article, I find daily in C without using functions. It takes 365 days for the earth to revolve around the sun. It will be close to...

3 minutes read.

strcat() Function in C

Strings in c: A string is defined as the set of characters that are enclosed within the double quotations (" "). The String always ends with the null character ("\0"). The...

3 minutes read.

2f in C language

Float data type in c: Double-precision floating-point numbers with up to 17 significant digits are stored in the FLOAT data type. FLOAT is equivalent to C's double data type and IEEE...

3 minutes read.

Fibonacci series program in C using Recursion

In this tutorial, we’ll explore how to utilise recursion to build the Fibonacci sequence in C language. What does the term "Fibonacci Series" mean? The following number in a Fibonacci number series is...

2 minutes read.

Escape Sequence in C

An escape sequence is a sequence of character that used inside the string literal or character.  All the escape sequence is used with the backslash (\) symbol. The list of an...

1 minute read.

Fibonacci series in C

We have learned about the Fibonacci series in mathematics. For a quick recap, A Fibonacci series is the sequence of numbers following a certain pattern i.e., the next number should...

3 minutes read.

Goto and Labels in C

Introduction Goto in C: The goto statement is known as the jump statement in C. The goto is used to transfer the control of a program to a predefined label. The goto...

3 minutes read.

Array to function in C

Array to function in C We can create functions that receive an array as an argument. To pass an array into a function, we need to write the name of the...

4 minutes read.

Call Back Function in Embedded C

Callback function are one the most remarkable systems in C. A callback function is any code that is passed as a contention to another code, so this is the last...

3 minutes read.

fflush in C

In this article, we will understand what is fflush(), the need for fflush and fflush(stdin), and fflush(stdout). The fflush() function is used to clear the output buffer and move the buffered...

3 minutes read.

Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling

In this article, you will learn how to initialise an array to 0 in C In C, an array is declared as: char ZEROARRAY[2022]; The global scope changes at runtime to all zeros....

3 minutes read.

Queue implementation in C

In the C programming language, the queue is the abstract concept that is similar to stacks. However, it is the part of the data structures that work opposite to that...

4 minutes read.

Dos.h Header File in C Language

Dos.h is a header file in C. Interrupt handling, sound generation, date and time functions, and other tasks can be performed using the functions in this library. This is exclusive to...

4 minutes read.

C and C++ Binary Files

What is a binary file? A file in which the content is written in binary format is called a binary file. A binary file is not a text file. There are...

7 minutes read.

#error #pragma in C

#error, #pragma in C #error, also known as the error directive in the C language. It will not allow you to make any compilation fail and immediately issues a statement which...

4 minutes read.

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

4 minutes read.

First Fit Program in C

This is one of the easiest ways to allocate memory. The main goal is to divide the memory into several fixed sizes. In C, there is only one process for...

3 minutes read.

How to convert a string to hexadecimal in C

Converting a character array or any string to its respective hexadecimal form is simple. The only thing we have to do is to follow the below steps. Take each character from...

3 minutes read.