Sunday 20 May 2012

What is user define function? Mention some advantages.


        C functions can be classified into two categories, namely, library functions and user-define functions. Main is an example of user defined functions. Printf and scanf belongs to the category of library functions. The main distinction 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. However, a user define function can later become a part of the C program library.
The main advantages of user-defined functions are given bellow:
1.     The complexity of the entire program can be divided into simple subtask and then function subprograms can be written for each subtask.
2.     The subprograms are easier to write, understand, and debug.
3.     A function can be shared by other programs by compiling this function separately and loading and linking them together.
4.     In C, a function can call itself again. It is called a recursive function. Many calculations can be done easily by using recursive functions such as calculation of factorial of a number, etc.
5.     Reduction in size of program due to program code of a function can be used again and again, by calling it.
6.     A library of a function can be designed and tested for use of every programmer.

No comments:

Post a Comment