📅  最后修改于: 2022-03-11 14:48:12.092000             🧑  作者: Mango
ReturnType FunctionName(FormalParameterList)
{
Statements ;
return ReturnValue;
}
1. ReturnType describes the type of value that will be returned by the function. In the case of myAbs, we want the function to return an integer, so the return type is int.
2. FunctionName is the name of the function that we want to call. The rules for what are legal names of functions are exactly the same as for variables. (Take a look back at Lesson 3 for the legal names for variables.)
3. ParameterList specifes the parameters that the function will take. If there are no parameters, the parentheses are left empty. Otherwise the type and the name of (each of) the parameter(s) is specified. If there is more than one parameter (the standard library function pow is an example of such a function) the parameters are separated by commas. A parameter list looks similar to the declaration of one or more variables.
4. Statements represents any number of valid C++ statements. (Note that we always use braces to specify the body of a function, even if there is only one statement in its body.)
5. The return statement specifies the value that is returned by the function. ReturnValue can be a variable or an expression, but its type must be the same as ReturnType specified in the function header. For example, if ReturnType is float, then ReturnValue must represent a floating point number.