Page 3 - Sample_test_Float
P. 3

Functions and Pointers  3


              Consider another example,
                                                       sum(x,y) = x + y.
              where
                sum is a function name
                x,y is an argument or input of function
                x+y is a definition of a function.
              When x = 2, y = 3,
                                                      sum(2,3) = 2+3 = 5
              Here 2,3 are arguments and 5 is the return value.


              5.1.1. Introduction to Functions
              Functions are a block of statements (called modules) that perform a specific task assigned by the user.Functions
              accept an input, perform a task and produce the output.




                               Input                    Function                     Output




              Function reduces the redundancy of code.It breaks down a large program into small modules to improve read-
              ability and portability as well as to make the program easy to debug.
              Functions can be categorized into two types:

              1.  Pre-Defined function
              2.  User Defined function


              Pre-Defined vs User Defined

               Pre-Defined Function                            User Defined Function
               Pre-defined functions are library functions.    User defined functions are the function which are created
                                                               by users as per their ownrequirements.

               Pre-defined functions are part of header file(such as   User defined functions are part of the program which is
               math.h) which is called runtime.                called during compiling.
               Name of function can’t be                       Name of function can be changed any time.
               changed.
               The declaration and definition of afunction is already   User is going to declare and define that function in the
               known to the compiler.                          program.



              5.1.2. Need for Functions
              If we want to execute a block of statements again and again repeatedly, then we have to repeat the block of
              statements again and again, which will increase the size of program code, but if we place the block of state-
              ments that will be repeated inside the function, then we need not repeat the block of code again and again,
              instead we can just call the function again and again.
   1   2   3   4   5   6   7   8