Steps for C++ Program Development and Execution

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:

  1. Editing
  2. Compiling
  3. Linking Library files
  4. Loading
  5. Execution

Let us understand each point with an example,

Steps for C++ Program Development and Execution

Editing:

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.

Compiling:

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.

Linking Libraries:

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.

Loading:

To execute the program code, the code must be brought to the main memory from the secondary memory.

Execution:

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 Management

Main memory has different sections.

  1. 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.
  2. Stack: All the variables (that are used for storing the data values) are stored in the stack section of the code.
  3. 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.

Leave a Reply

Your email address will not be published.