C Function

Description

Functions provides modularity to the software.

Syntax

The general format of a function is


<Return type>   <Function name>   <Parameter list>{
     local definitions;/*from   w  ww.j a v  a 2s .c  o m*/
     statements;
     Return value;
}

Example

The following code defines a function called add. It adds two integer type value together and returns the sum to the caller.


#include <stdio.h>
// www. ja  va2 s  . c o  m
int add (int x, int y) {
    int z;          
    z = x + y;
    return (z);     
}
main ()
{
    int i, j, k;
    i = 10;
    j = 20;
    k = add(i, j);       
    printf ("The value of k is %d\n", k);  
}

The code above generates the following result.





















Home »
  C Language »
    Language Advanced »




File
Function definition
String
Pointer
Structure
Preprocessing