FUNCTION AS BUILDING BLOCK/MODULAR PROGRAMMING IN C

MODULAR PROGRAMMING

Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules ,such that each contains everything necessary to execute only one aspect of the desired functionality.

             ____________________________

             ____________________________

  •  A function prototype is like writing the first line of the function except you replace the contents between the curly braces with a semicolon.
  • The prototype tells the compiler how to pass parameters to the function that found somewhere else and how to get results back form it. Prototypes unused function do not hurt anything.

Prototype: A C program lines that declares a function found either later in the program or in another module.

  • ANSI standard for C suggest that all functions be prototyped ahead of main() function. Then the actual function code is put after the main function or in another module. This makes more programs lines , but it does fit the idea of top-down programming.
  • However , putting the actual function in reverse calling sequence and before the main function always works and avoids some unnecessary lines.
  • It is clear that a single file or "module" is sufficient to hold the entire C program.
  • Modular programming , however, is a "module" software design and programming technique which break -up a large program into manageable subprogram units as function and subroutines . 
  • Modular programming also helps in debugging and testing program and reduce the likelihood of bugs . Local scopes of variable in modules and smaller size of the individual modules make it easier to understand the effects and impacts of changing a variable.
  • Modular programming in C is to organize a program in multiple files. There is a main module which contains the main () function. This is the entrance of the entire program and many other modules in formats of C source code files or header files .

**ADVANTAGES  OF MODULAR PROGRAMMING*-----

1) Code Reusability :

                                       The repeated instructions can be placed within a single function, which can then be accessed whenever it is needed . Moreover,a different set of data can be transferred to the function each time it is accessed .

2) Library Generation:

                                           The use of function also enable a programmer to build a customized library of frequently used routines or of routines containing system- dependent features .Each routine can be programmed as a separate function and stored within a special library files .If a program requires a particular routine,the corresponding library function can be accessed and attached to the program during the compilation process .

3) Recursion :

                            Many iterative (i.e., recursive) problem can be written in this form . Recursion is process by which a function calls itself repeatedly ,until some specified condition has been satisfied . The process is used for repetitive computations in which each action is stated in terms of a previous results.


In order to solve a problem recursively,two conditions must be satisfied:

I) The problem must be written in a recursive form ,and 

II) The problem statement must include a stopping condition.

4) Top down approach:

                                             It facilitates top - down modular programming. In this programming style, the high level logic of the overall problem is solved first while the details of each lower-level function are addressed later. 

_____________________________________________

Thanks.....







Comments

Post a Comment

Popular Posts