Page 66 - DCAP404 _Object Oriented Programming
P. 66

Unit 3: Review of Functions




                 }                                                                              Notes
                 long  sum(long  a,  long  b)
                 {
                         return  (a  +  b);
                 }
                 float  sum(double  a,  double  b)
                 {

                         return  (a  +  b);
                 }
          Overloaded functions have the same name but different number and type of arguments. They
          can differ either by number of arguments or type of arguments or both. However, two overloaded
          function cannot differ only by the return type.




              Task  In overloaded functions, the function call determines which function definition
             will be executed. Explain with an example.

          Self Assessment

          Fill in the blanks:
          6.   Function overloading is a feature of C++ that allows us to create ………………. functions
               with the same name, so long as they have different parameters.
          7.   Overloaded functions have the same name but different number and…………………. .
          8.   If a function call fails to compile by the number and type of argument(s), the compiler
               reports the same as……………….  .
          9.   Function overloading  can  lower  a programs  …………………….. significantly  while
               introducing very little additional risk.
          10.  Member function declarations with the same name and the name parameter-type-list
               cannot be ……………………. if any of them is a static member function declaration.

          3.3 Inline Functions


          C++ provides facility of inline function, which is designed to speed up the program execution.
          This is done by the C++ compiler, which incorporates it into a program.
          When  any  program is  compiled the  output of  compilation  is  a  set  of machine  language
          instructions, which is in executable program. When a program is run, this complied copy of
          program is put into memory. Each instruction gets a memory address, which is used to refer that
          instruction. These instructions are executed as per the logic in the  program. Instructions  are
          executed step by step unless there are any loop or branching instructions. When there is branch
          or jump instruction, some instructions are skipped and forward or backward jump is made.
          In normal function call, the control of execution is transferred to the location where the function
          is loaded in memory that is the starting executable instruction of the function. When all the
          instructions of the function are executed the control returns back to main program from where left.




                                           LOVELY PROFESSIONAL UNIVERSITY                                   59
   61   62   63   64   65   66   67   68   69   70   71