Program that executes source code without a separate compilation step.
In this unit, we will delve into the process of how a program runs on a computer. This involves understanding the roles of compilers and interpreters, the concept of source code, object code, and executable code, and the different types of errors that can occur during the process.
When you write a program, you write it in a high-level language that humans can understand. However, computers can only understand machine language, which is a low-level language. The process of translating high-level language into machine language is done by a compiler or an interpreter.
A compiler takes the entire program written in high-level language, translates it into machine language, and saves it as an object code (also known as binary code). This object code is then linked to create an executable file that can be run on a computer.
An interpreter, on the other hand, translates the high-level language into machine language line by line as the program is running. It does not create an object code or an executable file.
Source code is the program as it is written by the programmer. It is written in a high-level language and is readable by humans.
Object code is the result of the source code being translated by the compiler. It is written in machine language and is not easily readable by humans.
Executable code is the linked object code that can be run on a computer. It is also written in machine language.
Errors are common in programming and are a part of the learning process. There are three main types of errors that can occur:
Syntax errors: These are mistakes in the language of the program. They can be as simple as a missing semicolon or as complex as a missing closing bracket. Syntax errors prevent the program from being compiled or interpreted.
Runtime errors: These errors occur during the execution of the program. They are often caused by illegal operations such as dividing by zero or trying to access an array element that does not exist.
Logical errors: These are the most difficult to detect. They occur when the program runs without crashing, but produces incorrect results. Logical errors are often due to mistakes in the program's logic.
Understanding how a program runs on a computer is crucial for anyone learning to code. It helps you understand the process your code goes through before it can be run and the potential issues that can arise during this process.