Below are some of the features of a C++ function
Syntax:
return_type function_name( parameter list )
{
body of the function
}
The definition of a C++ function typically consists of a function header and a function body. These parts of a function are listed and described below:
A function may be used to return a value. The return type function returns the data type of the value of the function. However, some functions perform such operations without returning a value. So, therefore, the return type is the keyword void.
These indicate the true name of the function. In addition, the function name and the parameter list, both constitute the function signature.
During programming, once a function is invoked, a value is passed to the parameter. Hence, this value could be referred to as the true parameter or argument. However, the parameter list refers to the data type, order, and a number of parameters of a function.
Though, parameters are optional. This means that functions may not contain any parameter.
This function typically contains a collection of statements that define the actual thing the function does.
Example:
#include <iostream>
// function declaration
int max(int num1, int num2);
int main ()
{
// local variable declaration:
int a = 99;
int b = 97;
int ret;
// calling a function to get max value.
ret = max(a, b);
cout << "Max value is : " << ret << endl;
return 0;
}
// function returning the max between two numbers
int max(int num1, int num2)
{
// local variable declaration
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}