FUNCTIONS


C is a structured programming language. We have been using functions from the beginning without knowing what actually are they. We have used the functions printf( ), scanf( ), getch( ) in our programs, but we never thought of how they are actually defined and where they are defined.

DESIGNING STRUCTURED PROGRAMS

The programs we have presented so far have been simple. They solve the problems that could be understood without too much effort. As we consider larger programs you will discover that it is not possible to understand all aspects of such programs without somehow reducing them to more elimentary parts. Breaking a complex program into smaller parts is a common practice. First you must understand the problem as a whole then, you must break it into simpler, understandable parts. We call each of these parts of a program, a module and the process of sub-dividing a problem into manageable parts is top-down design.

In top-design a program is divided into a main module and it’s related module. Each module is in turn divided into sub-modules, until the resulting modules are intrinsic i.e,until they are implicitly understood without further division.

Top-design is usually done using a virtual representation of the modules known as structure chart. This chart shows the relation between each module and it’s sub-modules

The main module is known as the calling module because it has sub-modules. Each of these sub-modules is known as a called module.
But, because module 1,2,3 also have sub-modules, they are also called calling modules.
Communication between modules in a structure chart is allowed through a calling module. If module 1 needs to send to send data to module 2, the data must be passed through the calling module(main module). No communication takes place directly between that do not have a calling-called relationship.

Copyright © 2018-2020 TutorialToUs. All rights reserved.