C function definition

Function Definition in C Programming | Defining a function

What is Function Definition in C Programming ?

  1. Function definition is nothing but actual Function.
  2. Function Call is short term used, however function definition is “Actual Broad Elaboration” of function call.
  3. Function definition is different from macro expansion.
  4. It contain Executable Code ( Executable statements )
  5. First Line is called as Function Header .
  6. Function Header should be identical to function Prototype with the exception of semicolon
  7. Argument names has to specify here !!
function definition in c Programming

Syntax : Function Definition in C Programming

return-type function-name(parameters)
   {
   declarations
   statements
   return value;
   }

Different Sub parts of Above Syntax :

return-type
  1. Return Type is Type of value returned by function
  2. Return Type may be “Void” if function is not going to return a value.
function-name
  1. It is Unique Name that identifies function.
  2. All Variable naming conversions are applicable for declaring valid function name.
parameters
  1. Comma-separated list of types and names of parameters
  2. Parameter injects external values into function on which function is going to operate.
  3. Parameter field is optional.
  4. If no parameter is passed then no need to write this field
value
  1. It is value returned by function upon termination.
  2. 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