C Language

Function Definition

In C Language by Baqir AliLeave a Comment

The block of code that defines the working of a function or defines what a function does? A function definition has two principal components.

  • The function header (including the   parameter declarations)
  •  and the so-called body of the   function

A function definition and has the following general form:


Dissecting a function

The function header

The function header takes the general form:

  r_type f_name(type1 prm1, type2 prm2, ..., type2 prm2)


 r_type represents the data type of the item returned by the referenced function, f_name is the name of the function. prm1, prm2 ,..., prmN are the parameter names, type1, type2 ,..., typeN are the data types of the parameters of the function. 

Example 1

int add(int a, int b)
   int sum;
   sum = a + b;
   return sum;
void main (void)
   int x = 4, y = 20,  z;
   z =  add (x , y);
   printf ( “The sum is  %d \n ”,  z);

Output is:

The sum is 24

Get The Coding Examples From C Language Code Example Page

Leave a Comment