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:
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!