Section 2.5 Compiling C++ Programs
The programming language you will learn in this book is C++, which is a high-level language. A high-level language is one that allows the programmer to write code that is abstracted from the physical details of the computer it will run on. When using one of these languages, the programmer does not have to worry about what machine instructions the CPU supports, or how the CPU specifies particular addresses in memory. Most programming languages used by programmers are high-level ones. Some examples you may have heard of include Python, Java, or JavaScript.
Computers canβt actually run code in high-level languages. Before they can run, programs in high-level languages have to be translated into a low-level language, also called βmachine languageβ. This translation takes some time, which is a small disadvantage of high-level languages. But high-level languages have two major advantages:
-
It is much easier to program in a high-level language. Programs take less time to write, they are shorter and easier to read, and they are more likely to be correct.
-
High-level languages are portable, meaning they can run on different kinds of computers with few or no modifications. Low-level programs can run on only one kind of computer.
Two kinds of programs translate high-level languages into low-level languages: interpreters and compilers. An interpreter reads a high-level program and executes it, meaning that it does what the program says. It processes the program a little at a time, alternately reading lines and performing computations. Languages like Python and Javascript are often interpreted.
In contrast, a compiler reads the entire program and translates it completely before the program starts running. The high-level program is called the source code. The translated program is called the object code, or the executable. Once a program is compiled, you can execute it repeatedly without further translation of the source code. As a result, compiled programs often run faster than interpreted programs.
Although it might seem complicated, these steps are automated for you in most development environments. Usually, you only have to press a button or type a single command to compile and interpret your program. On the other hand, it is important to know what steps are happening in the background, so if something goes wrong you can figure out what it is.
Checkpoint 2.5.2.
You have attempted of activities on this page.