Examples of function definitions

The following example is a definition of the function sum:

int sum(int x,int y)
{
   return(x + y);
}

The function sum has external linkage, returns an object that has type int, and has two parameters of type int declared as x and y. The function body contains a single statement that returns the sum of x and y.

The following function set_date declares a pointer to a structure of type date as a parameter. date_ptr has the storage class specifier register.

void set_date(register struct date *date_ptr)
{
  date_ptr->mon = 12;
  date_ptr->day = 25;
  date_ptr->year = 87;
}