Differenper e Between Compile Time and Run Time in C
Categories: AWS(Amazon Web Services)
Difference Between Compile Time and Run Time in C
Introduction
Computers understand only binary language, If we want to communicate with computers, we have to use binary language. Imagine writing a program to add two numbers in just 1's and 0's. Sounds impossible, right? To overcome this problem, we write codes in a high-level language. Writing a program in a high-level language might be easy for us, but the computer doesn't understand the high-level language. To fix this problem, we make use of compilers. A compiler translates the entire program written in a high-level language to machine language before execution.
Let us take an example of a robot. The robot responds to a set of commands for which they are programmed. Suppose you give a command for which the robot is not programmed. The robot won’t do anything but go blank. Even computers understand only a few words; if you say something the computer does not know, it'll get confused and shows an error.
With this basic knowledge, It will be easy for us to understand compile-time vs run-time errors.
Before jumping into the difference between compile-time vs run-time errors, Let us understand what is compile time.
What is Compile Time?
Compile time is the period when the programming code is converted to the machine code.
In the above illustration, We can see that a compiler converts the High-level language into low-level language. If there are any errors in the high-level language, the compiler shows a compilation error.
Compile-time errors
These are the errors that occur at the time of compilation. There are mainly two types of Compile-time errors.
- Semantic errors.
- Syntax errors.
- Semantic errors
The code having absurd meaning refers to semantic errors. In other words, meaningless statements are termed semantic errors.
Syntax errors
Syntax refers to the rules that define the structure of a language. The syntax error is an incorrect construction of the source code.
What is Run Time?
So far, in our compile time vs runtime journey, we have understood what compile-time is. Now let us understand what is run-time?
Runtime is the period of time when a program is running and generally occurs after compile time.
Examples of Compile-time Errors and Run-time Errors
Now that we have understood the basic definition of the errors, what is compile time vs runtime, types of errors in compile time vs runtime let's look at some examples to make the concepts clear.
- Compile-time errors
- Syntax errors
Syntax errors can be of different types, Such as
Missing semicolon.
Missing Parenthesis (}).
Printing the value of a variable without declaring it.