A function definition is the actual implementation of the  function. The definition contains the code or program that will be executed.

Let us understand the function definition in detail with example from the given diagram.

  Function Definition and its Elements.
Let us understand the user defined function definition from the Given Diagram.
In C programming language the Function definition consists of Function Header and function body.
1. Function Header:  the function header is the signature of the function, provides detail information about the function.
Function Signature  the function signature is the combination of a function's name and its types of parameters and return type.
Function signature allows the compiler to understand how the function should be used and called in the program.
Funtion definition actually is the body of the function .
Following are the elements of Function definitions
1. Return Type:  This can be any valid C data types if the function returns C valid data type values or void if the function does not return any value to the calling environment or function.
2. Function Name: This is unique identifier or name to the function.It is used to call the function in the program.
3. Parameters: Parameters are enclosed in parentheses and can have their own data types and names.
Parameters are the optional inputs that function can accepts.
If the function have multiple parameters they are seperated by commas.
2. Function Body:  function body is the block of code where the programmer can write the actual implementation action or computational task. the function executes the task written in the body when the function get called.
The function body is the actual code or task of the function that defines the behaviuor of the function.
The function body is where you define the logic that the function perform. Function body can have various structure defined inside.
for example control stataements,looping statements,variable declaration ,calculations or computations etc.
Function body is executed when the function is called, and the result can be used or returned as needed.


A function body example in C:

int addition(int p, int q)
{
int total;
total=p+q;
return(total);
}

Explanation:
In the example given above, the function body starts with the opening ({) curly brace and ends with the closing (})curly brace .
Inside the function body, we have a variable declared int total and an
assignment statement that calculates the sum of the two input parameters p and q(total=p+q).
Finally, the function returns the computed total using the return statement return(total);.

1. C program to illustrate function Definition.

/* function to find addition of a two number */
#include<stdio.h>
int addition(int p,int q)   //Function Definition/Declaration
{
  int total;
 total=p+q;
 return(total);
}
int main()
 {
  printf("\n Addition=%d",addition(5,3));
  return 0;
 }
Output:
Addition=8
Explanation:
int addition(int p,int q)
{
  int total;
 total=p+q;
 return(total);
}
is the function Definition and declaraion.
addition is the function which takes two integer parameter p,q and return integer value.
In the function body{ } the addition total=p+q of two int input
parameter p and q are performed and total is returned ( return(total) ) to calling program.
we called the addition(5,3) function in main program inside printf() which gives result Addition=8.


Previous Topic:-->> Elements of User Defined Function in C || Next topic:-->>Function Declaration/Prototype.
Other Topics: