Previous Slide Parts of a function Next Slide

Functions in C++ follow this basic format:
return-type functionName(parameter-list)
{
  body
}

  • The return-type specifies what type (e.g., int, float) of value is returned. Functions that don't return a value have a return type of void.

  • The name of the function must be an valid identifier (like variable names). For example, func_name or funcName, but not func-name (- is not a valid identifier character).

  • The parameter-list is a comma-separated list of the type and name of values that will be passed to the function. For example, int a, int b, char ch. If a function takes no parameters, it should have an empty parameter list ().

The return-type, function name and parameter-list form the header of the function.


BU CAS CS - Functions
Copyright © 1993-2000 by Robert I. Pitts <rip@bu.edu> All Rights Reserved.