Value-Returning Functions

  • A value-returning function is a program routine called for its return value and is therefore similar to a mathematical function.

Example

  • Function name: avg
  • Takes three arguments: n1, n2, and n3
  • Calculates and returns the average of the three arguments.
  • Function call example: avg(10, 25, 16) evaluates to the calculated average.
  • Return statement: return expr where expr is the expression that holds the result.
Design a site like this with WordPress.com
Get started