Loading...
C

Function Definition

Function Definition : A function definition specifies the function name, type and number of parameters to receive, and its return type. It also includes a function body with the declaration of its local variables, and the statements that determine what the function does
Syntax :
return_type function_name(parameters_list)
{
Function_body;
}
The first line return_type function_name(parameter_list) is known as function header and the statements within the curly braces is called function body.

  • Return Type – A function may return a value. The return type is the data type of the value the function returns. Some functions also perform the desired operations without returning a value. In this case return type is the keyword void.
  • Function Name- This is the actual name of the function. The function name and the parameter list together constitute tge function signature.
  • Parameters-A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to a actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of the function.

Parameters are optional; that is, a function may contain no parameters.

Function Body – It is the collection of statements that define what the function does.
EXAMPLE :
int sum(int num1, int num2)
{
int num3;
num3=num1+num2;
return (num3);
}

Leave a Reply

Your email address will not be published. Required fields are marked *