What is a Function ? Explain Different types of Functions?


Functions are a self contained block of code that performs a particular false. A function can take some data from the main program, and returns a value.

The large program is divided into functional parts, and then each part may be independently coded and later combined into a single unit. These independently coded programs are called programs and are referred as function.

C functions can be classified into 2 categories, namely

   1.    library functions and
   2.    User –defined functions

main ( ) is an example of user defined function.

printf & scanf belong to the category of library functions.

The main difference between these two categories is that library functions are not required to be written by us, Whereas a user defined function has to be developed by the user at the time of writing a program.

Advantages of Functions:

1.When the program may become too large and complex and as a result the task of debugging, testing, and maintaining becomes difficult.

If a program is divided into functional parts, then each part may be independently coded and later combined into a simple unit.

These independently coded programs are called subprograms that are much easier to understand, debug, and test.

2.In some situations, we may repeat the program statements at many points throughout a program.

In such case, if you design a function that can be called used whenever required. This saves both time and space.

The length of source program can be reduced by using fns at appropriate places.

3.It is easy to locate and isolate a faulty function for further investigations.

4. A function may be used by many other programs. A user –defined function can later become a part of the C program library

functions


Top down modular programming using functions.




Related

C Language 4934666576100036981

Post a Comment

emo-but-icon

item