C Programs generally follow a set structure which has six different sections.
- Documentation section
- Link section
- Definition section
- Global declaration section
- Main function section
- Subprogram structure
Let’s understand them one by one.
- Documentation Section – It contains the information about the program, but it is not compiled by the compiler.
- Header or Link Section – This includes all the important library functions for the program to be executed.
- Definition Section – It defines all symbolic constants.
- Global Declaration Section –Variables used in more than one function are known as Global variables and are defined in the global declaration section.
- Main Section – Every C program must have one main function. Two parts of this section are
- Declaration Section – Variables used in executable parts are declared in this section.
- Executable Section – There should be one statement in the execution section.
Declaration Section and Executable section begins with opening braces ( { ) and ends at closing braces ( } ).
All the statement in both these sections ends with a semicolon (;).
6. Sub-program Section – It contains all user-defined functions which are called in the main function. User-defined functions can appear in any order but generally, they are placed immediately after the main function.
Let us now see an example code to find the area of circle.
/*Program to find the area of the circle */
#include<stdio.h>
main()
{
float rad, area;
printf("Enter the Radius = ");
scanf("%f",&rad);
area=3.14*rad*rad;
printf("Area of circle is %f",area);
}