Page 41 - Touchcode_C8_Flipbook
P. 41

Coding          uiz    01                                                           Critical Thinking


                    State whether the following statements are true (T) or false (F).

                    a.  A function is a block of code that result in a single specific action.


                    b.  Function decreases the chances of writing the code again and again
                        in the program.




                 FUNCTION PARAMETERS
                 Function parameters are the variables local to the function, taken as input to do a task when
                 the function is called, they are part of the function definition. Arguments are the values that

                 are passed on to the function received by the function as a parameter. A function can have
                 more than one parameter, and in this case order in which arguments are passed matters.

                 So, Function parameters are the names listed in the function  definition  and Function
                 arguments are the real values passed to (and received by) the function.



                   Example:
                   To calculate the volume (V) of a cuboid, you need three variables length (L), breadth (B)

                   and height (H). The formula to calculate the volume of a cuboid is V = L * B * H.
                   You can make a function named VolumeOfCuboid which takes parameters L, B and H.

                   Now the function will look like:
                   VolumeOfCuboid (L, B, H)

                   {
                   return L * B * H
                   }



                 In the above example, you only need to provide the value of:

                    Length (L)
                    Breadth (B)
                    Height (H)

                 Thus, the variables accepted by a function to perform the set of tasks defined in its body are

                 called function parameters.






                                                                                           Functions in Depth    39
   36   37   38   39   40   41   42   43   44   45   46