Function Definition : Defining a Function in C Programming
Function Definition in C Programming | Defining a function
What is Function Definition in C Programming ?
- Function definition is nothing but actual Function.
- Function Call is short term used, however function definition is “Actual Broad Elaboration” of function call.
- Function definition is different from macro expansion.
- It contain Executable Code ( Executable statements )
- First Line is called as Function Header .
- Function Header should be identical to function Prototype with the exception of semicolon
- Argument names has to specify here !!
Syntax : Function Definition in C Programming
return-type function-name(parameters)
{
declarations
statements
return value;
}Different Sub parts of Above Syntax :
return-type
- Return Type is Type of value returned by function
- Return Type may be “Void” if function is not going to return a value.
function-name
- It is Unique Name that identifies function.
- All Variable naming conversions are applicable for declaring valid function name.
parameters
- Comma-separated list of types and names of parameters
- Parameter injects external values into function on which function is going to operate.
- Parameter field is optional.
- If no parameter is passed then no need to write this field
value
- It is value returned by function upon termination.
- Function will not return a value if return-type is void.
Note : The return statement forces the function to return immediately though function is not yet completed
Live Example : Function Definition in C Programming
Way 1 :
#include<stdio.h>
int sum(int n1,int n2)
{
return(n1+n2);
}
int main()
{
int num1=11,num2=22;
int result;
result = sum(num1,num2);
printf("\nResult : %d",result);
return(0);
}Explanation of Live Example :
| Function Nane | sum |
|---|---|
| Return Type | Integer |
| Calling Function | main |
| Parameter Passing Method | Pass by Value |
| No of Parameters Passed to Function | 2 |
| Actual Parameter 1 | num1 |
| Actual Parameter 2 | num2 |
| Formal Parameter 1 | n1 |
| Formal Parameter 2 | n2 |
| Function Will Return | n1+n2 |
| Returned Value will be Catch in | result |





