Page 76 - 6437
P. 76

if (num1 > num2)

                                   result = num1;
                                else
                                   result = num2;


                                return result;

                            }

                          We have kept max()along with main() and compiled the source code. While running the
                   final executable, it would produce the following result:


                 Max value is : 200


                          Function Arguments
                          If a function is to use arguments, it must declare variables that accept the values of the
                   arguments. These variables are called the formal parameters of the function.
                          Formal parameters behave like other local variables inside the function and are created
                   upon entry into the function and destroyed upon exit.
                          While  calling  a  function,  there  are  two  ways  in  which  arguments  can  be  passed  to  a
                   function:


                         Call Type                  Description


                         Call by value              This method copies the actual value of an argument into
                                             the formal parameter of the function. In this case, changes made
                                             to  the  parameter  inside  the  function  have  no  effect  on  the
                                             argument.



                         Call by reference          This method copies the address of an argument into the
                                             formal  parameter.  Inside  the  function,  the  address  is  used  to
                                             access  the  actual  argument  used  in  the  call.  This  means  that
                                             changes made to the parameter affect the argument.

















                                                                                                      79
   71   72   73   74   75   76   77   78   79   80   81