Programming Structure of 'C'


 Programming Structures of 'C'

Every language has a definite program structure which must be followed to write and execute the program successfully in that language. The “C” has the following program structure:-
(i) Documentation Section                Optional 
(ii) Link Section                             Essential
(iii) Definition Section                    Optional 
(iv) Global Declaration Section            Optional
(v) main( ) program Section                 Essential
{
Declaration part 
                Executable part
}
(vi) User Define function Section Optional 
f1( )
{
        ………………
        ………………
}
f2( )
{
        ………………
        ………………
}

(i) Documentation Section:- In this section we can write the extra statement a part from the program code. The extra data statements may have the date of creation, purpose of program, working of each module etc.
The extra statements must be enclosed either by using following two symbols.
          //
        /* ……………..*/
All the statements enclosed within above two symbols are called as comments.

        // :- Used for single line.

        Ex:- // ……………..
               //……………..

         /*….*/ :- Used for multiple line.

        Ex:- /* ……………..
                     ……………..  */
The commented statements are ignored by the compilers so there is no any effect of commented statements at run time. They can be seen only in the source code.

(ii) Link Section:- In this section we use the header files within program. 
          Header file is a collection of several predefined functions having extension ".h". So we can say that header file is a container of containing the predefined functions.
            If we want to use any predefined function within program then we must have use the corresponding header file also.
            Syntax:-    #include<header file name>
    The preprocessor directive (#) opens the "C" library at first and then the "include" keyword search the specify directory in the library and add it with own program it found otherwise raise an message.
        Ex:-     #include<stdio.h>         //  stdio - Standard I/O
                    #include<conio.h>        //  conio - Console I/O
                    #include<math.h>         
                    #include<stdlib.h>        //  stdlib - Standard Library
                    etc.

(iii) Definition Section:- It is an optional part and it is use to create a macro by using "#define" statement.
            Syntax:-    #define macroname value
        The macroname may be any user defined name and it can hold any types of value. When the macroname is used within program then its value is automatically submitted at that place.
            Ex:-    #define a 10                    //    a is macroname
                        #define s "RAM"           //    s is macroname
                        #define ram Sita            //    ram is macroname

(iv) Global Declaration Section:- It is also an optional part and it is used to create the global variable.
            Ex:-    #include<stdio.h>
                       #define A 10
                        int x;                // Global Variable
                        float y;            //   Global Variable
                        main( )
                        {
                            .........................
                            .........................
                        }
        The global variables can be used from anywhere within the program.

(v) main( ) program  Section:- Every "C" program must have one and only one main( ) function because the execution of the program starts from the main( ) function only.
    A program which has no main function cannot be executed.
            Syntax:-    main( )
                            {
                                Declaration Part;
                                Executable Part;
                              }
    Declaration Part:-    In this part we can declare the variables. These variables. These variables are called as local variables. The scope of local variables is limited within the module only i.e. the local variables can be used within that module only under which they have been declared.
       Executable Part:-    In this part we can write the executable statements.

Note:-  The declaration part must be written before executable part.
            Ex:-    main( )
                      {
                            //Declaration part
                            int a;
                            float b;
                            char c;
                            //Executable part
                            c = a + b;
                            printf( ............................);
                        }

All variables declare within a function is a Local variable of that function and it can be used only within that function.

(vi) User Defined Function Section:- It is an optional part which is used to create any number of user define function. This section is used to implement the structured programming technique.

Post a Comment

0 Comments