C Program Structure

In order to write C programs we have to follow some basic structuring rules of c programming language. Now to explain the structure of c language, lets take an example of C code :
#include <stdio.h>

int main() {

  printf("Hello world.!!\n");
  return 0;

}
Output :

Hello world.!!

Pre-processor :

#include is a pre-processor, which tells the compiler to include header files. #include is the first word of any C program. So the statement #include<stdio.h> instruct the compiler to include stdio.h header file.

Header file :

A Header file is a collection of built-in functions, which we can directly use in our program. Header files contain definitions of the functions which can be incorporated into any C program by using pre-processor #include statement with the header file. To use any standard functions like printf(), scanf() we must need to include the header file in  our c program source code. For example, to use the printf() function in a program, which is used to display anything on the screen, the line #include <stdio.h> is required because the header file stdio.h contains the printf() function. All header files will have an extension .h.

main() function :

When we run a c program, then the execution of program will begins from the main function. main() function is a function that must be there in every C program. Everything inside this function in a C program will be executed. The opening curly bracket '{' and closing bracket '}' denotes the starting and ending of main function. In the above example int is written before the main() function, which denotes the return type of main() function. We will discuss more about it letter.

Return Statement :

the return statement terminates the main() function and returns the some value. In the above example the return statement returns value 0.


Next Topic :