The basic structure of c program with an example [Easy notes]

C program basic structure

Today, we understand the basic structure of the C program. How you can implement your code in c compiler.

Let’s understand it with an example-

/*Header files - Pre-processive directories 
that have definition of all build-in 
functions, macros, keywords etc.*/

int main() //main function of a program
     //variable declaraction
     int i,j,k;
     clrscr(); //this function is used to clear the console 
     //program code here
/*this function display the 
output result until you press any key.*/

//Note: C and C++ both are block structural language and always terminate each statement with a semi-colon.

Let’s understand the above code step by step

Header Files

Header files are pre-processive directories that have a definition of all built-in functions, macros, keywords etc. We use the header file name followed by #include. e.g. #include<stdio.h>

Generally, we use two header files in each c program.

  • #include<stdio.h>
  • #include<conio.h>

stdio.h is responsible for standard input and out functions
conio.h is responsible for console related functions

Main() function

The main program tells the compiler to execute the program from here. Every c program must cater to this main() function. It can contain a number of program code statements and they are executed one by one.

basic structure of c program

Variable declaration

When you type main() function and start your code; first you need variable declaration if program needed. Variable declaration syntax is-

<data_type> var_name1,var_name2… ;

clrscr() function

clrscr() function is used to clear the console screen. You can use it anywhere in your program code.

getch() function

getch() function is used to hold the output screen until you press any key. conio.h header file contains definition of this function.

Generally, it reads one char, and returns it as an int

Hope that you understand the basic structure of c program. If you have any questions please don’t forget to ask in below comment section.

If you like this code helpful don’t forget to share this in your social family.

Related post

What is variable in C language? An interview question
What is a C programming language [exam oriented answer]

If you like technology blog post please visit

Leave a Comment

Show Buttons
Hide Buttons