General Structure of C program

Basic Structure of a C program contains following sections,

Documentation Section
Link Section
Definition Section
Global Declaration Section
main()
{
Declaration Section
Executable part
}
Subprogram section
Function 1
Function 2
.
.
function n

The Documentation Section consists of a set of comment lines giving the name of the program and other details.

The Link Section provides instructions to the compiler to link functions from the system library.

The Definition Section defines all symbolic constants.

Start exploring endless computing possibilities with your own Raspberry Pi computer and accessories. Perfect for beginners and students.

The Global Declaration Section: There are some variables and those variables are declared in this section that is outside of all functions.

main() function: Every C program must have one main function section. This section contains two parts, declaration and executable part.
Declaration Part declares all the variables used in the executable part.
There should be at least one statement in the executable part which contains instructions to perform certain task.
The declaration and executable part must appear between the opening and closing braces. All statements in the declaration part should end with the semicolon.

The Subprogram Section contains all the user defined functions that are called in the main function.

Example Program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*Documentation Section: program to find the area of circle*/
#include "stdio.h"   /*link section*/
#include "conio.h"  /*link section*/
#define PI 3.14     /*definition section*/
float area;          /*global declaration  section*/
void main()
{
float r;                /*declaration part*/
printf("Enter the radius of the circle\n");   /*executable part starts here*/
scanf("%f",&r);
area=PI*r*r;
printf("Area of the circle=%f",area);
getch();
}

25 Responses to “General Structure of C program”

Leave a Reply