Skip to main content

13.2) Defining And Calling Functions


Function Definitions

  • Functions must have a name that follows the usual variable naming conventions of C++
  • The name is preceded by a return type, specifying what type of value the function will return to its caller; use void if the function doesn't return anything
  • The name is followed by round brackets, which can be empty if no data needs to be passed in to the function when it is called; any required inputs are specified by including a comma-separated list of parameters inside the brackets
  • Function parameters must be given a name and a type
  • Function parameters act as variables that are local to the function

Function Calls

  • Functions are invoked or called using their name, followed by round brackets
  • The brackets should be empty if the function requires no parameters; if it requires parameters, arguments should be supplied that are compatible with those parameters