In this article Basic Structure of C Program we give the information about basic structure of c program with example and related one program.
Basic Structure of C Program:
Documentation section |
Link section |
Definition section |
Global declaration section |
main() function section
{ Declaration section Executable section } |
Subprogram section
Function 1 Fun2 (User-Defined functions ) Function 3 ———- ———- ———- Function n |
Documentation section: –
The documentation section contains a set of comment lines giving the name of the program, the name of the author and other details, which the programmer wants to use later.
There are two ways to provided comments in program such as single line comments (//) and multiline comments(/* —— */).
Link section: –
The link section use for provides instructions to the compiler to link the function from the system library.
Definition section: –
Definition section defines all the symbolic elements.
Global Declaration Section: –
In some cases there are some variables which are used in more than one function. Such variables are called global variables and are declared in the global declaration section outside of all declarations.
This section also declares all user-defined functions.
Main () Function Section: –
Each C program must have a main () function section.
This section has two parts, the declaration part and the executable part.
The declaration part necessary for declares all the variables used in the executable part.
There is at least one and more statement in the executable part.
These two parts must appear between the opening and closing windows.
The execution of the program begins in the opening bracket and ends in the closing bracket.
The closing bracket of the main function section is the logical end of the program.
All statements in the declaration and actionable area end with a semicolon (;).
Subprogram section: –
The subprogram section advantages to its contains user-defined functions called main functions.
User-defined functions are usually placed immediately after the main function, although they may appear in any order.
// Write a program to find Area of circle – Documentation Section
#include<stdio.h> // link section
#include<conio.h>
# define PI 3.142 // Definition Section
float main()
{
float r; // variable Declaration
clrscr(); // library function
printf(“\n Enter the radius=”);
scanf(“%f”,&r);
printf(“\n Area of Circle=%.3f”,PI*r*r);
getch();
return 0;
}
O/P:-
Enter the radius= 1.0
Area of Circle= 3.142
Some More:
POP- Introduction to Programming Using ‘C’
OOP – Object Oriented Programming
DBMS – Database Management System
RDBMS – Relational Database Management System
Join Now: Data Warehousing and Data Mining