Functions - Example for Category III of functions*/

/* Example for category III of functions */

# include < stdio.h >
Add ( a, b )
int a,b;
{
int c;
c=a+b;
return c;
}

main( )
{
int x,y,z;
printf (" \n Enter the value for  x & y " );
scanf( "%d%d", &x, &y );
z=Add( x, y );
printf ( " \nResult is %d", z );
}


In the above program, initially x and y variables are declared and values for x and y are accepted. Then Add(x,y); line indicates that we are calling a function Add and passing two parameters x and y(where x & y are actual arguments). In function Add, copies actual argument x &y are copied into formal argument a and b. They are added and result is stored into c and returned to the calling function main. In main it is received by variable z and further it can be used in any expression.

Comments