Leaf subroutine

Leaf subroutine (leaf function):

  • Leaf subroutine/function = a subroutine/function that does not contain a subroutine/function call

 

Example: square( ) is a leaf function


   // square( ) is a leaf function   

   int square(int x)     
   {
      return x * x;  // No function calls
                     // used in the function 
   }
   

Non-leaf subroutine

Non-leaf subroutine (leaf function):

  • Non-leaf subroutine/function = a subroutine/function that contains one or more subroutine/function calls

 

Example: sumOfSquare( ) is a non-leaf function

   int square(int x) 
   {
       return x * x;
   }


   // sumOfSquare( ) is a non-leaf function    
   int sumOfSquare(int x, int y) 
   {
       return square(x) +  square(y);
   }