Explain Basic Structure of C Program with Example

In this tutorial, You learn about the basic structure of C program and also brief descriptions of all 6 sections with the help of an example.

Let us understand the basic structure of C program with example and diagram first how the programming structure of c program looks like and it set image in the mind of the programmer as we know that if we learn a thing with images easy as compare to the theory and then learn with a brief explanation of all sections. 

Basic structure of C program

The basic structure of the program is divided into six components. Below we describe the basic structure of C program in detail. Try to give answers to all common questions related to this. The below diagram shows all sections in the sequence are:

basic structure of c program
Basic Structure of C Program

Above we see the image which shows all the sections whose combined to make a perfect indenting c programming language which shows the clarity of the basic structure of C and it helps you in the future if you a beginner when you see other codes or someone see your code then it is easy to understand that where is the global declaration section, definition section, and so on. This basic structure of c is global and the same for all programmers. 

Basic Structure of C Program Explain

C documentation section


/*
 * Author: Veer Bhadra

 * File: areacircle.c

 * Description: Find area of circle
 */


This section contains multi-lines comments description documentation of code which shows about the author, file name, date, description of code, and other important pieces of information.

Link Section


#include<stdio.h>

This is known as include information about the standard library. We link header files to the program that is required. Header files are files with .h extensions. It gives instructions to the compiler to link functions from the system library to the program. Examples: stdio.h, stdlib.h, math.h, string.h, etc.

Definition


  #define PI 3.14

All the symbolic constants are written in the definition section. We use #define (preprocessor compiler directive) to create constantly. 

Global Declaration Section


float areacircle(int r); 

The global section is used to declare the user define functions declaration. It is also used to declare global variables and both can be used anywhere in the program.

main() function


main()

{
   variable declaration
   execution part
}


The main function is a special function in the program why main() is special? because main() is the only function which presents in each and every program and the execution of the program from the beginning of main(). main function excepts no arguments which indicate an empty list.
Each declaration and execution parts are ended with a semicolon(;).

Subprogram


float areacircle(int r)
{
  return PI*r*r;
}

In this section, we define the functions that are declared in the global section to perform specific tasks or user-defined functions are called from the main function. 

In this tutorial, We discuss the basic structure of C program and also brief descriptions of all 6 sections with the help of an example. If you have any doubts about this then comment below

Happy Coding😍

No comments:

If you have any doubts, Please let me know

Powered by Blogger.