In this post we will learn to create, edit, compile and run our First C Program.
Whenever we talk about the first program in C language, most programmers first make the “Hello World” program.
You can also say that this is like a tradition and we will also make our first c program “Hello World” by continuing this tradition.
- 1 How to Compile and Run C Program in CodeBlocks
- 2 You can also read: Introduction to Python Programming Language
- 3 First C Program Structure Explanation
- 4 C Header Files
- 5 C Indentation
- 6 Without Indentation C Program:
- 7 With Indentation C Program:
- 8 You can also visit my Hindi YouTube Channel.
How to Compile and Run C Program in CodeBlocks
Step 1. First of all, open the codeblocks compiler on your computer.
Step 2. Now you will open an empty file on the new option by clicking on the file menu.
Step 3. Now you have to write the below given source code in that file. I would suggest you do not copy yours and write the code yourself after seeing it.
You can also read: Introduction to Python Programming Language
Step 4. Now you have to save this program at any location on your computer.
I would suggest that you create a folder on your computer with C programs or any other name and save your program in it.
Step 5. Now you have to compile this program and for this you have to go to the menu bar.
As soon as your C program is compiled, then you will have to click on the View menu in the logs and click on the logs option as below.
Step 6. When your C program will be successfully compiled without any errors, after that you will have to click on the Build menu in the menu bar and click on the logs option.
As soon as your C program is run, your C program output will be shown on the new window.
First C Program Structure Explanation
We have successfully compiled and run our first c program above and now we will understand the structure of that program.
If I tell the truth, the truth is that you will fully understand the structure of this first c program when your C language will be about 80% complete.
We have used indentation, comments, header file, main function and printf function in our first c program above. We have written very detailed tutorials on all this, which you will get to read further.
Here I am just giving you a basic idea of Header files and Indentation, which will make it easier for you to understand the structure of C programs.
C Header Files
In our first c program, #include a preprocessor command on line 2 ie this means that the compiler will include the stdio.h header file before compiling your program.
The stdio.h header file contains declarations of all standard input and output related functions of C language such as printf() and scanf() functions.
In C programming, before using any built-in functions in your program, you are required to include the header file in which the declarations of those functions are present.
Do coding using any programming language, the most important thing you have to take care of is Indentation.
Programs without indentation are not readable for any programmer, that is, there are many problems in understanding the source code of programs.
Giving the correct indentation in the source code makes it easier to understand the programs and find errors in them. Giving indentation is considered a good programming practice.
To give indentation while creating programs, we use the tab key in the keyword. I have created 2 programs below.
Indentation is not used in the first program given below and indentation is used in the second program.
You do not yet have to understand the logic of the programs given below. You just have to see and understand why it is important to give indent while creating programs.
Without Indentation C Program:
With Indentation C Program:
I hope that you have liked this post. If you liked the post, then please share it with your friends and relatives and you can send your suggestion in the comment box below or email me at email@example.com.