Compilation and Execution in C

In this  C tutorial, you will learn to start your IDE to write your first program. Also, you will learn various ways to compile and execute the program in an elegant way.

Starting your IDE

To start writing your first program in C, you need to start the code block IDE. Follow the below steps for creating a new C file.

  1. Open Code Block
  2. Go to File Menu ----> New------>File.  A window as shown below will pop up asking what type of file you want. In our case, we choose the option C/C++ source and GO.
    Code block Installation
  3. Choose C and click on the Next button
    Code block Installation
  4. Specify the path where you want to create your file and name it and then click on the finish button.
    Code block Installation - Path
  5. Code block IDE looks something like this after finishing file creation.
    Code block Installation - Create File

In the text editor section, you can create your desired program and then save the program for future use. To save the program you can either use the shortcut keys Ctrl+S or the Save icon in the toolbar.

Code block Installation

Compile and Execute C Program

After program creation, the next important action to be done is the Compilation and Execution of C programs. Compilation simply means checking whether the program created is syntactically correct or not. Execution means running the code to produce an output.

Here we will discuss how Compilation and Execution can be performed using CodeBlock in the Windows environment step by step.

In CodeBlock we have a build icon to compile the programs and a run icon to execute the programs. If we want to compile and run in one go there is another option named build and run icon available at the toolbar. In addition, a rebuilt and abort icon is also available. All these options make the users work hassle-free.

Code block - Run Icon

The other way to operate build and run is by going to the menu bar build where all the options and its shortcut keys are available.


After saving the program you have to compile the program using any of the above options, we use Ctrl+F9. All messages after compilation will appear in the Build Log tab of the log Windows underneath the text editor area. You will see something like this:

Code block - Log

Here you can see there are no errors but 2 warnings. Errors can be syntactic errors or exceptions which halt the program from the compilation. Once we encounter an error we need to resolve it first to proceed further. While warning tells you the indication that you are doing something wrong and either you can rectify it now or leave it as it is and rectify it later. Warning never halts the compilation.

Now you can run your program which will give you a  window as shown below. All your output will be displayed in this window.

Code block - Run Progrm

Note: Make sure to close this window by pressing any key on the keyboard. Keeping this open disables the build and run activity in the CodeBlock.