0% found this document useful (0 votes)
7 views3 pages

Basic Structure of A C Program1

The document outlines the basic structure of a C program, which consists of six sections: Documentation, Link, Definition, Global Declaration, Main Function, and Subprogram. Each section serves a specific purpose, such as providing program identity, including libraries, defining constants, declaring global variables, and executing the main logic of the program. An example program to calculate the area of a circle is provided to illustrate these sections in practice.

Uploaded by

Rajasomeshwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Basic Structure of A C Program1

The document outlines the basic structure of a C program, which consists of six sections: Documentation, Link, Definition, Global Declaration, Main Function, and Subprogram. Each section serves a specific purpose, such as providing program identity, including libraries, defining constants, declaring global variables, and executing the main logic of the program. An example program to calculate the area of a circle is provided to illustrate these sections in practice.

Uploaded by

Rajasomeshwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Basic Structure Of A C Program:

Structure of the C program is divided into six different sections.

1. Documentation section: The documentation section consists of a set


of comment lines giving the name of the program, the author and other
details, which the programmer would like to use later. These information
give the program an identity and basic authority.

/*
* comment goes here
*/

2. Link section: The link section provides instruction to the compiler to


link or include the required in-built functions from the system library such
as using the #include directive. This is important, because if we need to
use any in-built system function we must first include the library in which
the function has been defined.

Ex: #include<stdio.h>
3. Definition section: The definition section defines all symbolic
constants using the #define directive. Having the constants being defined
here, we can use them elsewhere in code.
4. Global declaration section: There are some variables that are used
in more than one function; these variables are called global variables and
are declared in this global declaration section which is outside the
definition of any function This section also declares all the user-defined
functions. As this global scope, these functions and variables can be used
from definition of other functions.

5. main () function section: A C program must have one main function


section in its structure. This section contains two parts; declaration part
and executable part. However, the content of these two parts can be
mixed.

void main()
{
Declaration part;
Executable Part;
}
1. Declaration part: The declaration part declares all
the variables used in the executable part.
2. Executable part: There is at least one statement in the
executable part. These two parts must appear between the opening
and closing braces of the main function. 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.

6. Subprogram section: If the program is a multi-function program then


the subprogram section contains definition of all the user-defined
functions which were declared earlier in the Definition Section. User-
defined functions are generally placed immediately after the main ()
function, although they may appear in any order.
EX: WAP to find the area of a circle

/* program – Area of a circle Documentation Section

Author – Santosh

Date – 25 th dec 2021 */

#include<stdio.h> Link Section

#define pi 3.14 Definition Section

void main() Main function section

float r,area; Declaration part

printf(“enter r value”); Executable part

scanf(“%f”,&r); Executable part

area=pi*r*r; Executable part

printf(“Area of circle =%f”,area); Executable part

You might also like