0% found this document useful (0 votes)
37 views

How Does A C++ Program Executes

When a C++ program is compiled, it generates several files: 1. The source code file (.cpp) is compiled into an object file (.obj) by the compiler. 2. The object file contains machine-readable code but is not executable. 3. The linker links the object file to library functions to create an executable file (.exe) which can be run by the CPU. 4. When the .exe file is executed, the loader loads the program into RAM and tells the CPU where to start running the code.

Uploaded by

Ali Ammar Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

How Does A C++ Program Executes

When a C++ program is compiled, it generates several files: 1. The source code file (.cpp) is compiled into an object file (.obj) by the compiler. 2. The object file contains machine-readable code but is not executable. 3. The linker links the object file to library functions to create an executable file (.exe) which can be run by the CPU. 4. When the .exe file is executed, the loader loads the program into RAM and tells the CPU where to start running the code.

Uploaded by

Ali Ammar Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

How does a C++ program executes?

Whenever a C++ program file is compiled and executed, the compiler generates some
files with the same name as that of the C++ program file but with different extensions.
So, what are these files and how are they created?
Below image shows the compilation process with the files created at each step of the
compilation process:

Every file that contains a C++ program must be saved with ‘.cpp’ extension. This is
necessary for the compiler to understand that this is a C++ program file. Suppose a
program file is named, first.cpp. The file first.cpp is called the source file which keeps
the code of the program.
Compiler:
A C++ compiler is itself a computer program who's only job is to convert the C+
+ program from our form to a form the computer can read and execute (machine code).
The original C++ program is called the "source code", and the resulting compiled code
produced by the compiler is usually called an "object file".
When we compile the file, the C++ compiler looks for errors. If the C++ compiler reports
no error, then it stores the file as a .obj file of the same name, called the object file. So,
here it will create the first.obj. This .obj file is not executable. The process is continued
by the Linker which finally gives a .exe file which is executable.

Linker: First of all, let us know that library functions are not a part of any C++ program
but of the C++ software. Thus, the compiler doesn’t know the operation of any function,
whether it be cin or cout. The definitions of these functions are stored in their respective
library which the compiler should be able to link. This is what the Linker does. So, when
we write #include<iostream>, it includes iostream library which gives access to
Standard Input and Output. The linker links the object files to the library functions and
the program becomes a .exe file. Here, first.exe will be created which is in an
executable format.

Loader: Whenever we give the command to execute a particular program, the loader
comes into work. The loader will load the .exe file in RAM and inform the CPU with the
starting point of the address where this program is loaded.

You might also like