Compilation process of C program

Before we see how to compile and run a C program in code blocks. First, we need to understand the compilation process in detail. To understand this better, let’s have a look at the below image.


So, the compilation is a multistage process and compiler consists of mainly four components. They are:

  1. Preprocessor.
  2. Compiler.
  3. Assembler.
  4. Linker.

Let’s jump into these processes in detail:

  • Preprocessor : First we write the C program and save it with a .c extension. Then preprocessor removes comment(s) if any, from the source code. After that, #include directives and macros are expanded for example consider the code in the previous lesson. So, the header file stdio.h will get expanded. After all these processes the intermediate code is generated.
  • Compiler :In this step, the compiler checks the intermediate code for errors. If any error is there then the compiler will show errors in the form of warnings. And if it is error-free then the compiler will convert the intermediate code to assembly language program.
  • Assembler : Assembler then converts the assembly code to machine code or in low level language consists of 0’s and 1’s.
  • Linker : Now the role of Linker comes. The low-level code that we have right now, uses function(s) from the library. Then the linker will link the object code with the library. And ultimately generates the executable file with .exe extension.

Okay up to this point we have understood the compilation process, now we will see how to compile and run C programs in code blocks. In the previous lesson, we have seen a basic Hello World! program. Have a look at the below image.


Now to compile and run the C program you just have to press F9 which is a shortcut of build and run.For help you can see below image.


Now you will see the output of the c program something like this printing the Hello World!


In order to maintain this website, we need revenue from our ads. Without ads it is not possible to maintain this site. Please disable your ad blocker or whitelist this site!