Basic Structure of a C Program

Basic Structure of a C Program
If you are new to C programming and want to learn basics of c programming then this tutorial is for you. Before you speed up your learning in C programming, first you should take a look at basic building blocks of a c program.  Just look at the c program below and then understand basic structure step by step.

#include<stdio.h> 
#include<conio.h>
int main()
{
 printf("Technorials");
 getch();
 return 0;


Header Files


First Two lines in above program is known as header files. In C Library functions are grouped into header files. for example Standard Input and Output functions are grouped into stdio.h, Console Input/Output functions are grouped into conio.h, functions for mathematical calculation are grouped into math.h, so if we want to use a function from C Library then we first include particular header file. In Above Program we are using functions from stdio.h and conio.h. if you want to read more about it then you may visit tutorial on Header Files in C Language.

main function in C Language       


The Next Line in program int main(). All C Programming code runs inside the functions and main is the most important function in a c program. main function is the Entry Point in a C program.

int is return type of main function, when a function completes it can return a value back to calling function and the type of value it return is defined in function defination, thats why we have used return 0 at the end of main function.

printf("Technorials")


This C Statement will Display Technorials.com on Output Screen. printf() is function used to display or print output. printf function is defined in stdio.h header file, so to use this function in our program we have to include stdio.h in our program.

getch()


In some IDE like Turbo C++ if getch function is not used in your program then the output screen will be closed before you could see the output. getch function is used to get a character form keybord, we will use this function to hold the output screen till we press a character. this function is defined in conio.h

return 0


this statement belongs to the second line of program(int main()). return type of main function is defined as int, so at the end of main function we have to return an Integer value. 

; semicoln

 

; is known as statement tarminator. Every C statement must end with a ;

SHARE THIS
Previous Post
Next Post