Basic Structure of C Program With Examples | CsTutorialpoint

Basic Structure of C Program
Basic Structure of C Program

Basic Structure of C Program

Whenever we create a program in C language, we can divide that program into six different sections. This section is as follows:

  1. Documentation (Documentation Section)
  2. Preprocessor Statements (Link Section)
  3. Definition Section
  4. Global Declarations Section
  5. Main functions section
  6. User-Defined Functions or Sub Program Section

In C language, all these six sections together make up the Basic Structure of C Program. Now let’s learn in detail about all these sections -:

1. Documentation (Documentation Section)

Programmers write comments in the Documentation section to describe the program. The compiler ignores the comments and does not print them on the screen. Comments are used only to describe that program.

In the comments, programmer writes the name of the program, the author name which is making the program, and other information like – the date of the program, its purpose, etc. all These are written under the Documentation Section.

To know more about the comments in C language, see this -: Comments In C Language

Example -:

/* File Name -: Hello.c
   Author Name -: Jeetu Sahu Founder of CsTutorialpoint
   Date -: 05/05/2021
   Description -: A Program to find Odd or Even Number
*/

2. Preprocessor Statements (Link Section)

Within the Link Section, we declare all the Header Files that are used in our program. From the link section, we instruct the compiler to link those header files from the system libraries, which we have declared in the link section in our program.

Example -:

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <math.h>

In addition to all these Header Files in the Link Section, there are a lot of Header Files which we can link in our program if needed.

3. Definition Section

The definition of Symbolic Constant is defined in this section, so this section is called Definition Section. Macros are used in this section.

Example -:

#define PI 3.14

4. Global Declarations Section

Within the Global Declarations Section section, we declare such variables which we can use anywhere in our program, and that variable is called Global Variables, we can use these variables in any function.

In the Global Declaration section, we also declare functions that we want to use anywhere in our program, and such functions are called Global Function.

Example -:

int area (int x);  //global function
int n;            // global Variable

5. Main functions section

Whenever we create a program in C language, there is one main () function in that program. The main () function starts with curly brackets and also ends with curly brackets. In the main () function, we write our statements.

The code we write inside the main () function consists of two parts, one Declaration Part and the other Execution Part. In the Declaration Part, we declare the variables that we have to use in the Execution Part, let’s understand this with an example.

Example -:

int main (void)
{
 int n = 15; // Declaration Part
 printf ("n = %d", n); // Execution Part
 return (0);
}

6. User-Defined Functions or Sub Program Section

Declare all User-Defined Functions under this section.

Example -:

int sum (int x, int y)
{
  return x + y;
}

A Simple Program to the Find Area of ​​Circle in C Language

/* File Name -: area.c
   Author Name -: CsTutorialpoint
   Date -: 27/12/2020
   Description -:  A Program to find Area of Circle In C Language
*/
#include<stdio.h>           // Link Section
#define PI 3.14             // Definition Section
float r;                    // Global Declarations Section
float areaofcircle(float);  // Global Declarations Section
int main(void)              // Main functions Section
{
 float aoc;                 // Declaration Part
 printf("Enter the radius of circle");    // Execution Part
 scanf("%f",&r);                                  
 aoc=areaofcircle(r);
 printf("area of circle is %f",aoc);
 return (0);
}
float areaofcircle(float R)     // User-Defined Functions or Sub Program Section
{
  return (R*R*PI) ;
}

Output -:

Enter the radius of circle  5
area of ​​circle is 78.500000

Conclusion

Friends, I hope that you have found the answer to your question and you will not have to search about the basic structure of C language.

However, if you want any information related to this post or related to programming language, computer science, then comment below I will clear your all doubts 

Friends, if you liked this post, then definitely share this post with your friends so that they can get information about the basic structure of the C language.

To get the information related to Programming Language, Coding, C, C ++, subscribe to our website newsletter. So that you will get information about our upcoming new posts soon.

Leave a Comment