Functions - Examples on Categories of function

  /* Example for Category II */

/* TO ADD TWO NUMBERS */
Add(a,b)
int a,b;
{
int c;
c=a+b;
printf("\nResult:%d",c);
}
main()
{
int x,y;
printf("\nEnter the value for  x & y ");
scanf("%d%d",&x,&y);
Add(x,y);
}
 

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 we are calling a function Add and passing two parameters x and y(where x & y are actual arguments). In function Add, copy of values of x &y are copied into formal argument a and b. They are added and result is stored into c and printed. But result will not come back to calling function main.

Comments