Skip to main content

STRUCTURE OF A “C” PROGRAM


STRUCTURE OF A “C” PROGRAM:

The general structure of a C programming language is sub-divided into different sections. Those are
1. Documentation Section
2. Pre-processor Directive Section
a. Linkage Section
b. Definition Section
3. Global Variable Declaration Section
4. Main function
5. Local Variable Declaration Section
6. Executable Part
7. User Defined Section

DOCUMENTATION SECTION:
Documentation section is also known as comment section. Here, comment statements are non-executable statements. Comments are started by using “/*” and end with “*/”. Comments are used for the purpose of documentation within the program. There are two types of comments. Single line comments and multi line comments.

Ex:          /* My First Program */                                     // My First Program

PREPROCESSOR DIRECTIVE SECTION:

 In C language “#“ is called as pre-processor directive, it is defined as to do something before compiling the program. These are divided into two sections.
1.      LINK SECTION
Link section is used to include the header files, which contains definition for the standard library functions provided by C developers.
Ex: # include<stdio.h>
2.      DEFINITION SECTION
By using this we can define constant variables with its values.
Ex: # define PI 3.141

GLOBAL VARIABLE DECLARATION:
If you want to use a variable throughout the program, you need to declare variable as Global variable. Global variables are declared outside the main function. Global variables are automatically initialized with zero.

MAIN FUNCTION
main() is the important section in every C program. We cannot write programs without main() function. Execution starts from main() function. End of the main() function represents end of the program execution.

LOCAL VARIABLE DECLARATION:
Variables which are used in main() program are declared by using local variable declaration statement. These variables are available within the block only.

EXECUTABLE PART:
This section has reading, writing and processing statements having input or output functions, library functions, formulas, control statements.

USER DEFINED SECTION:
In this section we define functions called sub-programs which are called by calling statements from main() section. Every sub-program or function has local variable statements and executable statements similar to the main() program.

Ex: function or sub-program
              {
                 Statements;
              }

Example Program on C-structure:

/* Write a C Program to print Hai */

#include<stdio.h>
main()
          {
            printf(“Hai”);
            return 0;
         }


























Comments

  1. Computer Information - Computer Mobile Information is one of the leading computer and mobile, Internet, software and hardware knowledge providing website. You will get up to date information about computer and mobile free of cost. We also provide software and hardware solutions and services online free of cost. For more visit: Computermobile.info

    ReplyDelete
  2. Learn computer by knowing the merits and demerits of computer
    Demerits of computer

    merits of computer

    ReplyDelete

Post a Comment