Tech

Default Arguments–Functions–STRUCTURED PROGRAMMING Course Notes

Default Arguments

  • When a function is called repeatedly with the same arguments for a particular parameter, you can specify that such a parameter has a default argument. (default value to be passed to that parameter).
  • When a program omits an argument for a parameter with a default argument, the compiler inserts the default value of that argument to be passed to the function call.
  • Default arguments must be the rightmost (trailing) arguments in a function’s parameter list.
  • Default arguments are typically specified in the function prototype.
  • Note: Using default arguments can simplify writing function calls. However, some programmers feel that explicitly specifying all arguments is clearer.
  • Note: If the default values for a function change, all client code using the function must be recompiled.