Professional Documents
Culture Documents
Topics Covered:
1. declaration, definition and scope,
2. recursion,
3. call by value, call by reference.
Example:
float avg(int a, int b);
void swap(int , int); //argument name optional
void swap(int x, int y);
swap(int,int); //default return type is int
double Area(int r)
{
return PI * pow(r, 2);
}
int main()
{
printf("Area is %f", Area(5));
return 0;
}
}
C by Dr. Deepika Bhatia 15
2. Function with Arguments and no return value
e=c+d; // 10 ,34
printf(“result=%d”,e);
}
C by Dr. Deepika Bhatia 16
Tips
1.Type , order and number of actual and formal arguments must always besame.
2. It is not compulsory to usevariable names in the prototype declaration.
void sum(int , int);
3.No separatereturn statement was necessary to sendcontrol back
4. If the value of formal argument changed in the function the corresponding
change does not takeplacein the callingfunction
1. We don’t pass value, we pass address. void add(int *num) //pointer num
Address of var. is passed into function call as {
actual parameter. *num=*num+10; //value at num
2. In call by value, changes are made to the local copies of the arguments, while in
call by reference, changes are made at the addressvalues.
3. In call by value, old values are retained. In call by reference, old values are
updated with newvalues.
4. In call by value, changes are temporary but in call by reference, changes made
are permanent. C by Dr. Deepika Bhatia 27
Example of Call by Reference: WAP to change value 20 to 30