web analytics

Explain or Describe function definition.

Function Definition: 

The function definition is an independent program module that is specially written to implement to the requirements of the function. A function definition, also known as function implementation shall include the following elements

  1. Function name
  2. Function type
  3. List of parameters
  4. Local variable declarations
  5. Function statements
  6. A return statement
All the six elements are grouped into two parts; namely,
  1. Function header (First three elements)
  2. Function body (Last three elements)

Function Header

The function header consists of three parts; function type, function name and list of parameter.

(a) Function Type

The function type specifies the type of value (like float or double) that the function is expected to return to the calling program. If the return type is not explicitly specified, C will assume that it is an integer type.

(b) Function name

The function name is any valid C identifier and therefore must follow the same rules of formation as other variable names in C. The name should be appropriate to the task performed by the function.

(c) List of Parameter

The parameter list declares the variables that will receive the data sent by the calling program. They serve as input data to the function to carry out the specified task.


Example :
                                   Float mul (float x, float y) {….}
                                   int sum (int a, int b) {….}

Function body

The function body is enclosed in braces, contains three parts, in the order given below:

Local variable declaration: 

Local variable declarations are statements that specify the variables needed by the function.

Function Statements: 

Function statements are statements that perform the task of the function.

Return Statements: 

A return statement is a statement that returns the value evaluated by the function to the calling program. If a function does not return any value, one can omit the return statement.

    Thank you. Take a moment to share 🙏