Function Definition in C Programming

A function definition in C programming language consists of function name, function parameters, return value and function's body.

  • First line is called as Function Header and it should be identical to function Declaration/Prototype except semicolon.

  • Name of arguments are compulsory here unlike function declaration.

  • Function's definition contains code to be executed when this function is called.

Syntax of Function Definition

return_type function_name(type arg1, type arg2 .....) {
    body of a function
    return (expression);
  • return_type : The return_type is the data type of the value returned by the function. void data type is used when the function does not return any value. By default the return type of a function is integer(int).
  • function_name : This is a C identifies representing the name of the function. Every function must have a unique name in a C program. Name of a function is used to call a function.
  • type arg1, type arg2 ..... : It is a comma-separated list of data types and names of parameters passed by the calling function. The parameter list contains data type, order, and number of the parameters expected by a function at the time of calling it. Parameters field is optional, we can skip it if a function don't require any data from calling function.
  • body of a function : The body of a function contains a set of statements that will be executed when this function is called. It may define it's own local variables and call other functions.
  • return(expression) : This is used to send a value to calling function before termination of function. If the return type of function is void, you need not use this line. When control reaches return statement, it halts the execution of function immediately and returns the value of expression to calling function.
C Function Definition

C Program to show Function Definition


/* Function Defination */
int getAreaOfSquare(int side){
   /* local variable declaration */
   int area;
   area = side*side;
   /* Return statement */
   return area;

int main(){
   int side, area;
   printf("Enter side of square\n");
   scanf("%d", &side);
   /* Calling getAreaOfSquare function */
   area = getAreaOfSquare(side);
   printf("Area of Square = %d", area);
   return 0;
Above program finds the area of square using getAreaOfSquare function.

Enter side of square
Area of Square = 25