Functions 333
OUTPUT:
Enter Values of X & Y: 5 4
In changeO X= 4 Y=5
In mainO X=4 Y=5
Explanation In the above example we are passing addresses of formal arguments to the function
change (). The pointers in the change () receive these a d d re s se s () functions, that is, the pointer
points to the actual argument. Here the change () function operates on the actual argument through
the pointer. Hence, the changes made in the values are permanent. In this type of call no return
statement is required.
10.7 FUNCTION RETURNING MORE VALUES
So far we know that the function can return only one value per call. We can also force the function
to return more values per call. It is possible by the call by reference method. The following example
illustrates this fact.
10.17 Write a program to return more than one value from a user-defined function.
#in clu de<std io.h>
#include<conio.h>
main()
{
int x,y ,a dd ,sub ,c h ang e(in t*, in t*, in t * , in t *);
c lr s c r ();
printf ("n Enter Values of X & Y :");
scanf ("%d %d",&x,&y);
change(&x,&y,&add,&sub);
printf ("n Addition: %d ",add);
printf ("n Subtraction: %d ",sub);
return 0;
)
changetint *a, int *b,int *c,int *d)
I
*c=*a+*b;
*d=*a-*b;
OUTPUT:
Enter Values of X & Y: 5 4
Addition: 9
Subtraction: 1
Explanation In this program return statement is not used. Still the function returns more than
one value. Actually, no values are returned. Once the addresses of variables are available, we can
directly access them and modify their contents. Hence in the call by reference method, it is possible
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.166.255