Demystifying the Step-by-Step Execution Process of a C Program

Demystifying the Step-by-Step Execution Process of a C Program

Table of contents

No heading

No headings in the article.

Have you been wondering how files get executed in C and the files created in each stage until their actual execution?

Here is its comprehensive breakdown.

There are different stages involved in the execution of the C program.

The stages are shown in the simple flowchart below:

℅[https://www.google.com/imgres?imgurl=https%3A%2F%2Fstatic.javatpoint.com%2Fcpages%2Fimages%2Fcompilation-process-in-c3.png&tbnid=t5YfjWW5efm1WM&vet=1&imgrefurl=https%3A%2F%2Fwww.javatpoint.com%2Fcompilation-process-in-c&docid=97keSGyaD-GLiM&w=240&h=1041&itg=1&source=sh%2Fx%2Fim] [A flowchart showing the execution process of a C file]</a>

Here's a brief breakdown of the processes, first is the:

Source code stage

First of all, you save your program with the extension ".c" for example "hello. c". This is called the source code and this is done using any text editor e.g. vim, notepad++, sublime text, etc.

Preprocessing stage

The second concept is the preprocessor stage of execution. The preprocessor processes predefined functions as the compiler can not process headed files with the "#" symbol, header files like the #include <stdio.h>, it's the processor that helps process them into meaningful data for the compiler. The processor removes the #include files by expanding them and removing the # and declarations of the function to expanded source code or intermediary codes. Its extension, after the processor must have processed it becomes "hello. i". This file extension can now be assessed by the compiler for the continuation of the execution process.

Compilation stage

At the compiler stage the "hello. i" file passer from the processor is then further compiled into assembly files. At this stage, the compiler then generates a new file extension understandable by the assembler. The file extension generated by the compiler is the "hello. asm" file i.e. a file with the ".asm" extension. The compiler then passes it to the assembler.

Assembling stage

Assembler then processes the ".asm" files into object files with the extension "hello.o" This is done for the linker to be able to link these ".o" file extensions. This brings us to the linker stage

linking and execution stage

At this stage, as the name implies, is it the linking stage of the program? The linker helps to link all the ".o" files created by the assembler together into one executable file with the extension ".exe" for the computer's central processing unit to pass to the read-access-memory (RAM). This is done by the loader. The loader loads the files with the executable file extension ".exe" to the RAM for execution.

Which is the final stage of execution of the C program