Posted on 17th February 2014
Like variables, a function has to be declared before it can be used in the program. A function declaration has the following syntax
returnType functionName(arg_1_type, arg_2_type, .... arg_N_type);
- functionName is the name of the function. The rules for naming functions are same as that of naming the variables.
- arg_1_type, arg_2_type etc., are the data types of arguments that are passed to the function. They are enclosed in parenthesis and separated by comma. The argument declarations can be omitted completely which means the function can have any number of arguments.
- returnType is the data type of the return value. If the function returns no value then returnType is void
Function Declaration Example
int sum(int, int);
This declares a function named
sum which takes two integer type arguments and returns a integer value.
Post a comment