In the previous post, we had learned to write a basic C++ program. We should now understand how a program works and how the computer handles it.
Let us see the different phases a C++ program goes through before execution.
PHASE 1: PREPROCESSING
Preprocessor directive #include is used to include header files in our program. These header files contain declarations (name and type) of certain predefined elements (functions or objects) that we use in our programs.
These files are processed before compilation begins so that the compiler knows about the names and types of the predefined elements in advance.
After including the header files, the expanded source code is used for compilation.
PHASE 2: COMPILATION
We write our programs/source codes in the language we understand. But the computer understands only binary language.
The compiler is a program that converts our preprocessed source program into the language understood by the computer. After compilation, what we get is an object file.
PHASE 3: LINKING
The object file is linked with library files. Library files contain definitions(complete working code) of library functions and objects that we are using in our program.
The linker extracts these required definitions from the library file. The output of the linking phase is an executable file.
PHASE 4: EXECUTION
The executable file is a file with .exe extension. This is the final running version of the program (in language which the computer understands). When this file is executed, the output is produced.
The following flowchart depicts this complete process.
INTEGRATED DEVELOPMENT ENVIRONMENT (IDE)
Integrated Development Environment refers to an environment in which writing the source code and its compilation, linking and execution can all be performed at one place only.
In other words, in an IDE, the editor, compiler, debugger, linker etc are all present together at a single site which is quite convenient for a programmer.
Common examples of IDE are Microsoft Visual C++, Bloodshed Dev C++, Code::Block etc.
Hope you are clear with the concepts explained above. Do let us know about your queries through comments below.