Steps for C++ Program Development and Execution
In this article, I will give you a brief introduction to the steps involved in the development and execution of the C++ program. This is an important article. Here we will learn the steps involved in the development and execution of a program. So, what are the steps we will learn about those steps in detail and we will be using these steps every time when we are writing any program? There are 5 steps in the development and execution of the program:
- Linking Library files
Let us understand each point with an example,
Editing refers the typing or writing the program in any text editor. But we want all the things in one place like writing the program, compiling, and executing it. This is achieved with the help of software that is known as IDE (Integrated Development Environment). IDE integrated all the tasks that are required to run a program.
Examples of IDEs: Turbo C++, Devcpp, Xcode, Visual Studio Code, CodeBlocks, Eclipse, etc.
Consider a program first.cpp which is saved in Hard Disc. To compile the first.cpp file, we need an IDE that contains a compiler. The compiler converts the high-level code into machine-level language code and a new executable file with the name first.exe is generated and get stored in the hard disc. If the compiler finds any error in the code, it throws the error to the programmer else the code is successfully compiled.
Example: When first.cpp is compiled, the executable files are generated like max.exe and main.exe and get stored in the hard disc to get executed later.
Every language has some built-in objects and functions that can be reused in any program. The built-in objects and functions are grouped inside libraries that can be included in programs as header files. These libraries and header files are linked with the code during compilation where the library code is also converted to an executable file along with the entire program.
Example: We included iostream which is a header file for cout and cin objects. The iostream is attached to the code during compilation where the header file code is also converted to executable code with .exe extension. This is called the linking of the library.
To execute the program code, the code must be brought to the main memory from the secondary memory.
As soon as the program gets loaded in the main memory in different sections as given below, the program execution starts. The execution of the program starts from the first line of the main function.
Main Memory Management
Main memory has different sections.
- Code Section: The entire machine-level code is copied to the code section of the main memory. All the arrangements that are called relocations are done here and it is done by the operating system.
- Stack: All the variables (that are used for storing the data values) are stored in the stack section of the code.
- Heap: Heap memory stores the dynamically allocated variables, the variable that is allocated during the run time of the program (discussed later in detail).
Example: The variables in the program first.cpp are x and y is stored in the stack of main memory. The rest of the entire code is copied to the code section and the heap will be empty in this case as there are no dynamically allocated variables.
About the Author: Pranaya Rout
Pranaya Rout has published more than 3,000 articles in his 11-year career. Pranaya Rout has very good experience with Microsoft Technologies, Including C#, VB, ASP.NET MVC, ASP.NET Web API, EF, EF Core, ADO.NET, LINQ, SQL Server, MYSQL, Oracle, ASP.NET Core, Cloud Computing, Microservices, Design Patterns and still learning new technologies.