First C program in code blocks in a few simple steps

After you have installed code blocks, the next step is to write our first C program in it. So again, there are a few steps that we have to follow

  1. First when you launch code blocks you will see something like the image below.
code-blocks-in-windows
  1. Then click on Create a new Project as shown in the Image below:
C-program-in-code-blocks
  1. After doing so, a dialogue box will appear in the screen as shown in below image. Then click on the console application icon as highlighted in the image. Then select the go button.

First-c-program-in-code-blocks-in-a-few-simple-steps
  1. Another screen will open up like this in the image make sure you check the checkbox to avoid unnecessary dialogue every time you create a new project. Then click on next.
c-code-blocks
  1. After all, this step select the language, for now we are going to write C program so select it and click on next.
  1. Now enter your project name or you can say the name of the program and Choose path where the program is to be saved. After that proceed with next.
first-c-program-in-code-blocks
  1. Then finally click on finish.
first-c-program-in-code-blocks

This will open the sample program mentioned below. And don’t forget to remove #include<stdlib.h> header file which is not necessary. Our program will look something like the below example.

#include <stdio.h>
int main()
{
    printf("Hello world!\n");
    return 0;
}

Let’s understand each line of code in our first C program.

  • #include is a way to add Header files or user-defined files in any C program. It is usually present at the top of any program. A point to be noted that #include directive cannot be placed at the middle or end of the C program. stdio.h is a header file, so what is a header file now, it is nothing but basically is a file that contains C function declarations and macro definitions. Header files have the .h extension.
  • stdio stands for Standard input and output and contains printf( ) and scanf( ). printf() used to print the message on the output screen whereas scanf( ) is used to take input from the user we will see scanf( ) later in the program.
  • In the above-given program, main( ) is a function. When the Execution of program begins then the first function which is called is the main( ) function. It is the mandatory function in every program of C language.
  • As we talked before, the printf( ) will print the message of “Hello World!” in the output screen.

So, up to now, we have understood the basic C program. And in the next lesson, we will talk about the compilation and execution of C program in code blocks.

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!

YouTube
YouTube