C Structure
C Structure
The basic structure of a C program is given below. Any C program consists of 6 main sections.
1. Documentation Section
This section consists of comment lines which include the name of the program, the name of the
programmer and other details like time and date. Documentation section helps anyone to get an
overview of the program.
Example:
/* WAP to find the sum of 2 numbers
Author: Santosh Giri
Date: 01/01/2019
Time: 8 PM */
2. Link Section
The link section consists of the header files of the functions that are used in the program. It
provides instructions to the compiler to link functions from the system library such as using the
#include directive.
Example:
#include<stdio.h>
#include<conio.h>
3. Definition Section
All the symbolic constants are written in the definition section.
Example
#define PI 3.14
Example:
float area; //global declaration section
void display(); //function prototyping
Declaration part:
The declaration part declares all the variables used in the executable part.
Executable part:
There is at least one statement in the executable part. These two parts must appear
between the opening and closing braces. The program execution begins at the opening
brace and ends at the closing brace. The closing brace of the main function is the logical
end of the program. All statements in the declaration and executable part end with a
semicolon (;).
Example:
int main()
{
float r; //declaration part
printf("Enter value of r:"); //executable part start here
scanf("%f",&r);
area=PI*r*r;
printf("Area of the circle=%f \n",area);
display();
return 0;
}
6. Subprogram Section
The subprogram section contains all the user defined functions that are used to perform a specific
task. If the program is a multifunction program then the sub program section contains all the
user-defined functions that are called in the main() function. User-defined functions are generally
placed immediately after the main() function, although they may appear in any order.
Example:
void display()
{
printf("This message is from Sub Function named display \n");
printf("we can take more Sub Functions \n");
}
Total Program
//documentation section
/* WAP to find the sum of 2 numbers
Author: Santosh Giri
Date: 01/01/2019
Time: 8 PM */
Enter value of r: 3
Area of the circle = 28.260000
This message is from Sub Function named display
we can take more Sub Functions