Basic Structure of C Program with example explain

C program follows some basic Structure, So we will learn Basic Structure of C Program with example and with proper explanation.

Basic Structure of C Program

The program written in C language follows this basic structure. The sequence of sections should be as they are in the basic structure. A C program should have one or more sections but the sequence of sections is to be followed:

1. Documentation section 

2. Linking section 

3. Definition section 

4. Global declaration section 

5. Main function section 

6. Sub program or function section


In now let us discuss in detail.


DOCUMENTATION SECTION

DOCUMENTATION SECTION is used to document the use of logic or reasons in your program. It can be used to write the program's objective, developer and logic details. 

The documentation is done in C language with /* and */ . Whatever is written between these two are called comments.


LINKING SECTION


This section tells the compiler to link the certain occurrences of keywords or functions in your program to the header files specified in this section.

e.g. #include 

DEFINITION SECTION

It is used to declare some constants and assign them some value.

e.g. #define MAX 25

Here #define is a compiler directive which tells the compiler whenever MAX is found in the program replace it with 25.

GLOBAL DECLARATION SECTION

Here the variables which are used through out the program (including main and other functions) are declared so as to make them global(i.e accessible to all parts of program)

e.g. int i; (before main())


MAIN FUNCTION SECTION


It tells the compiler where to start the execution from.

main() 
    
        point from execution starts 
    

main function has two sections 
  1. Declaration section : In this the variables and their data types are declared. 
  2. Executable section : This has the part of program which actually performs the task we need. 

SUB PROGRAM OR FUNCTION SECTION


This has all the sub programs or the functions which our program needs.

Example of SIMPLE ‘C’ PROGRAM: 


Below is an Basic Structure of C Program with example.
    
/* simple program in c */

     #include <stdio.h>
      main()
      {
          printf(“welcome to c programming”);
      } 

/* End of main */

Comments

Popular posts from this blog

Implement Bouncing Ball Animation Using C Graphics

Walking Stickman -Using C graphics

Sine Wave - Using C Graphics