Introduction to Functions

Functions:

     A function is defined as a set of instructions that are used to perform specific tasks that repeatedly occur in the main program. then, the function normally called a sub-program that contains one or more statements and it performs some task when it is called.Every C program has at least one function which is main(). Function support modularity in software engineering. Similarly repetitive operation can be written as a function once and it can be used/invoked at several places where we want.


Type of Function:

     functions are classified into two types.
               
   1 .library Function
   2.User-defined Function                                                                                                                                                         

 

                            

Library Function:

     these library functions are the function whose functionality has been developed by the manufacturer of the software compiler & available to users for use. The user can only able to use the function but cannot modify anything in this function. But need to declare that functionality contains header files in preprocessor directives.

example;

cos, sin, tan..etc


User-defined    function :

           User dfined finction are function which going ti define , decalare and develop fully by the user at the time of writting a program based on his / her requirements. Here user can modify the function whenever wants. In this function user can implements and  modify their own ideas. These functions are used to break too large program into small functions.







 

                                       

 User-Defined function :

                                it is possible to write a large program into a small function. It is possible to write any complex program under the main () function but it creates many numbers of problem, such as 


 1.The program became too large & complex.

 2.Users can not go throw a single glance.

 3 .Debugging testing and maintenance tasks became more difficult.

if the same program is divided into small part then each part may independently be coded and later combined into a single program. This sub-program called a function.

Advantages of user-defined functions :

The length of the source program can be reduced by dividing it into smaller functions.

Using the function, it is very easy to locate and debug errors.

Code reuse :

A user-defined function can be used in many other source programs when we needed.

Function avoids repeated coding the same instructions.

It facilities a top-down programming approach.

Information hiding & improves maintainability.


Syntax:

  return_data_type function_name (arguments)

 {

   local declartions ;

   executable statement;

   return statement;

}










  





No comments:

Post a Comment