b. Derived Data Type


A function is a piece of code that performs some specific task when invoked in the program. It can be called from anywhere and any number of times in the program. The return value i.e., what type of value it will return depends upon the return type of the function.

In C, a function can be called by types: call by value and call by reference. When the function is called by value, a copy of the variable is passed as the argument whereas when the function is called by the reference, the address or reference of variable itself is passed to the function.


return_type function_name(parameters);

Description of the Syntax

  • return_type: This is the data type that specifies the type of value to be returned by the function. If the return type is void, then it is not mandatory for the function to return a value.
  • function_name: This is the name of the function. To specify the name of a function, you must follow the same rules which are applicable while declaring a usual variable in C.
  • parameters: The parameters are optional. They are passed according to the type of the function call.


The following example illustrates functions in C.

#include <stdio.h>

// function returning the maximum

// numbers between two integers.

int max_num(int num1, int num2)


    // local variable declaration

int res; 

if (num1 > num2)

res = num1;


res = num2; 

return res;


int main()


    // local variable definition.

int num1 = 225;

int num2 = 250;

int res;

     // function call.

res = max_num(num1, num2); 

    // print the result.

printf("Maximum number is : %d\n", res);

return 0;


The above example is comparing two numbers and finding the greatest among them. Here, we have passed two numbers that need to be compared, to the function by value. The function has an int return type so, it is returning the greater number after making a comparison.

Leave a Reply

Your email address will not be published. Required fields are marked *