C++ Functions Tutorial Continued:
C++ Functions
The functions that have a return value should use the return statement for termination. The main() function in C++ is, therefore , defines as follows:
int main()
{
………..
………..
return 0;
}
Since the return type of functions is int by default he keywords int in the main() header is optional. Most C++ compilers will generate an error or warning if there is no return statement. Turbo C++ issues the warning
Function should return a value
And then proceeds to compile the program. It is good programming practice to actually return a value from main().
FUNCTION PROTOTYPING
Function prototyping is one of the major improvements added to C++ functions. The prototype describes the function interface to the compiler by giving details such as the number and type of arguments and the type of returns values.
Function prototype is a declaration statement is the calling program and is of the following form:
| type function-name (argument - list) |
Examples:
float volume (int x, float y, float z);