functions in c
DESCRIPTION
Functions in CTRANSCRIPT
FUNCTIONS
Actual and Formal Parameters
Actual parameters – variables found in the function call whose values will be passed to the formal parameters
Formal parameters – variables found in the function header that will receive values from the actual parameters
#include<stdio.h>
Main()
{
int area,x,y;
x=25;y=10;
Area=Compute(x,y);
Printf(“%d”,area);
}
Compute(int L, int W)
{
int a;
A=L*W;
return a;
}
Actual parameters
Formal parameters
Call by value and pass by value
Call by value or pass by value – the values of the actual parameters are passed to the formal parameters. Changes that happen to the values of the formal parameters inside the function will not affect the values of the actual parameters
#include<stdio.h>
main()
{
clrscr();
x-=10;y=5;
printf(%d %d\n”,x,y);
pass(x,y);
printf(%d %d\n”,x,y);
getch();
}
pass(int a, int b);{ a= a+5;b=b*2;printf(“%d %d\n”,a,b);}