Basic Syntax of C program

In this tutorial, we will learn about the Basic Syntax of C program. Here will write our the first program in C programming. Let’s write a program in C.

Example Program:

#include <stdio.h>
int main() {
   //Our first program
   printf("Hello, World! \n");
   return 0;


Hello, World!

Elements of Example Program:

You can see the basic syntax of a C program. Now here we will learn about all the elements in our program and will understand what they do in this C program.

  • Pre-processor
  • Header file
  • main() Function
  • printf()
  • Comments


You can see we have written #include in the first line of the program. This #include is known as Pre-processor. These pre-processors are used to set up the environment for the c program. In our program pre-processor informing compiler to include stdio.h header file in our program.

Header file:

The c has a lot of inbuilt files which contain a lot of useful functions. These files are known as header files. As in the above program, you can see we have used printf() function to show Hello World on the screen. Can you guess from where we got this function? The answer is very simple we got this function from the stdio.h header file.

main() Functions:

The main function is something which would be part of all the C programs. It is important to note we right all our code inside this main function. As you can see we have written int before the main. Here int(data type) is working as the return type of our main function(we will discuss return type in our functions tutorial). After the main function, we have written starting bracket and some code inside {} brackets. The code inside {} of the main function is known as the body of the main function.print:


On the fourth line in the example program, you can see have written something like printf(“Hello, World! \n”);. Here printf() is a function which is part of stdio.h header file and this printf() function is used to show output on screen here in our program output will be Hello, World!.


On the third line in the example program, you can see have written something like //Our first program. When we write a single line statement with // in starting. It is known as comments in the C program and comments do not perform any task in the program. Comments are just to help programmers to remind about functions and variables etc.

Spread the love
Scroll to Top