Page 5 - Sample_test_Float
P. 5

Functions and Pointers  5


              6.  A function can call other functions andalso itself.
                 •  Function can call other function.
                 •  Function can call itself, which is called “recursive” function.
                 •  Recursive functions are also useful in order to write system functions.
              7.  It is easier to understand the program when a program is divided into small modules.
                 •  We can get overall idea of the program by just looking at the function names.


              5.1.4. Elements of a User Defined Function

              5.1.4.1. Function Name
              A function name is any variable name that the user gives to the function.

              Function naming rule
              •  Name of function includes only alphabets, digit and underscore.
              •  First character of name of function must be an alphabet or underscore.
              •  Name of function cannot be any keyword of c program.
              •  Name of function cannot be a global identifier(global variable name).
              •  Two functions cannot have same name within the scope.
              •  Name of function is case sensitive(abc and Abc are two different functions).

              5.1.4.2. Arguments/Parameter
              Arguments are nothing but the input that has been given to the function.The parameters can be passed to a
              function by two different methods.
              a)  Pass by value: In this approach only the copy of the actual variables is passed as aninput to the function.
                 Hence any modification done inside the function will not be reflected in the actual variable.
              b)  Pass by reference: In this approach the memory address of the actual variables is passed as a param-
                 eter to the function. Hence any modification done inside the function will be reflected in the actual
                 variable.

              Note: Argument should have a valid data type.
              Parameter: The names given in the function definition are called parameters.
              Argument: The values supplied in the function call are called arguments.


              5.1.4.3. Return Type
              The return type is nothing but the output or result obtainedafter the execution of the functions.
              •  Using return keyword output can be passed from the function.
              •  When the program control reaches the return keyword it immediately terminates the execution of that
                   function and transfers the control to the calling function.
              Note: A function can return only one value. Return type should be a valid data type.


              5.1.5. Various Blocks of a Function

              Any function needs to have the following three blocks.
              1.  Function Declaration – introducing the function to the compiler
              2.  Function Definition–defining the role of the function
              3.  Function Calling–calling the function


              5.1.5.1. Function Declaration
              •  Declaration of function in C is called Prototype Declaration.
              •  Function declaration is also called Function Prototype.
   1   2   3   4   5   6   7   8   9   10