Thursday 12 September 2013

function- part2

Advantages of the modular programming :

                (a) Easy to understand
                (b) Easy to debug
                (c) Easy to modify
                (d) Resuability of code.

(i) Pre-defined Functions : These functions are defined in the header files.

        e.g. stdio.h (printf() , scanf( ))

                conio.h ( clrscr( ) , getch( ) )

(ii) User-defined functions : These functions are defined by the user for there own prupose.

        These functions contains the following components :

                (a) Function Prototype.

                (b) Function call

                (c) Function definition

(a) Function Prototype : The function prototype is used to                                           specify the layout of the function.

The function prototype specifies the following information :

        (i) The function name

        (ii) The number of arguments the function requires

        (iii) The type of arguments

        (iv) The returntype.


The general form is ,

                returntype functionname(argument list);


Example 1 :

        int sum(int ,int);

        It specifies that there will be a function with the name
        sum( ) and this function will take two arguments and both are of type integers and the sum() will also return   the integer type value.

        float average(float,float,float);

        It speicifes that there will be a function with the name         average( ) and this function will take the three arguments     and all of them are of type float and the average( ) will   return the float type value .

        void show(char , int );
       
        It speicfies that there will be a function with the name         show( ) and this function will take the two arguments and the first argument will be of type char and the    second argument will be of the type int and the function         will not return any value.


(b) Function Call :

        Consider the following statement ,

                main( )
                {

                        ::      :       :       :       :

                        clrscr( );

                        :       :       :       :       :       :
                        :       :       :       :       :       :      
                }

                In the above mentioned code , we are calling the                 clrscr() function in the main( ) .

                The clrscr() function will be known as the Called                Function and the main( ) function will be known as the calling function .

No comments:

Post a Comment