When you create a program in C++, you write your code and execute it and see the result. But what happens behind the scenes? Between you writing the code and seeing the result there's a couple of things your computer takes care of in order for you to be satisfied.
To write a program in c++ you need an editor. While it is possible to write functional programs in notepad, life can get tremendously easier using an IDE. The advantages of using an IDE are integrating debugging, see warnings as you type, complete text automatically, and many more. All of these can save a lot of time.
The file you're writing your code with are referred to as source code, and ends with the .cpp extension.
When you're done writing code and want to see it perform, you tell the computer to compile it so you can use it. Before it compiles though, the source code have to be preprocessed. A preprocessor program, that is automatically executed, will look for preprocessor directives (starts with # in your source code) and include the contents of other files listed in these directives (i.e #include <iostream> will be substituted with its content). The preprocessing will produce a new file with the .i extension.
Now that the preprocessing is done, the compiler translates the .i file into machine-language code. This will produce an object file with the .obj extension.
A c++ program often consists of more than one file, one file can call functions from another. The compiler produces one .obj file for every source code you have. These files can't communicate with each other. It's the linkers job to connect these files and produce an executable program.
A program which is called loader will load the executable program to primary memory. This prepares the program to be executed one instruction at a time.
When everything is done, the program will execute and this is where you will see your masterpiece live.
Enjoyed this article? Give the teacher an apple.
Articles with similar tags